Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
If your not returning ruby primitives and other objects that know how to respond to #as_json from #as_jons - Your doing it wrong.
class User < ActiveRecord::Base
has_many :columns
def as_json(options={})
attributes.slice(:id, :email, :uuid).merge(:columns => columns)
end
end
class Column < ActiveRecord::Base
belongs_to :user
has_many :boxes
def as_json(options=nil)
attributes.slice(*JSON_ATTRS).merge(:boxes => boxes)
end
end
class Box < ActiveRecord::Base
belongs_to :column
has_many :bookmarks
def as_json(options=nil)
attributes.slice(:id, :column_id, :title, :style, :collapsed, :position).merge(:bookmarks => bookmarks)
end
end
class Bookmark < ActiveRecord::Base
belongs_to :box
def as_json(options=nil)
attributes.slice(:id, :owner_id, :owner_type, :url, :name, :position)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.