Created
May 18, 2011 01:52
-
-
Save metaskills/977846 to your computer and use it in GitHub Desktop.
If your not returning ruby primitives and other objects that know how to respond to #as_json from #as_jons - Your doing it wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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