aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/serializers/json_serializer.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2008-03-26 12:27:52 +0000
committerPratik Naik <pratiknaik@gmail.com>2008-03-26 12:27:52 +0000
commitca9413674ea70dc67ab517734af2e40dac21beef (patch)
tree86cbf305a2b1b4688a5b6f7cfbce8a9aa505c5f7 /activerecord/lib/active_record/serializers/json_serializer.rb
parent5c47ceb30b940a8cd8eb681a898895bce46f79dd (diff)
downloadrails-ca9413674ea70dc67ab517734af2e40dac21beef.tar.gz
rails-ca9413674ea70dc67ab517734af2e40dac21beef.tar.bz2
rails-ca9413674ea70dc67ab517734af2e40dac21beef.zip
Improve documentation.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9093 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/serializers/json_serializer.rb')
-rw-r--r--activerecord/lib/active_record/serializers/json_serializer.rb40
1 files changed, 17 insertions, 23 deletions
diff --git a/activerecord/lib/active_record/serializers/json_serializer.rb b/activerecord/lib/active_record/serializers/json_serializer.rb
index cf44309de7..c0a5850d5d 100644
--- a/activerecord/lib/active_record/serializers/json_serializer.rb
+++ b/activerecord/lib/active_record/serializers/json_serializer.rb
@@ -8,37 +8,32 @@ module ActiveRecord #:nodoc:
#
# konata = User.find(1)
# konata.to_json
- #
- # {"id": 1, "name": "Konata Izumi", "age": 16,
- # "created_at": "2006/08/01", "awesome": true}
+ # # => {"id": 1, "name": "Konata Izumi", "age": 16,
+ # "created_at": "2006/08/01", "awesome": true}
#
# The :only and :except options can be used to limit the attributes
# included, and work similar to the #attributes method. For example:
#
# konata.to_json(:only => [ :id, :name ])
- #
- # {"id": 1, "name": "Konata Izumi"}
+ # # => {"id": 1, "name": "Konata Izumi"}
#
# konata.to_json(:except => [ :id, :created_at, :age ])
- #
- # {"name": "Konata Izumi", "awesome": true}
+ # # => {"name": "Konata Izumi", "awesome": true}
#
# To include any methods on the model, use :methods.
#
# konata.to_json(:methods => :permalink)
- #
- # {"id": 1, "name": "Konata Izumi", "age": 16,
- # "created_at": "2006/08/01", "awesome": true,
- # "permalink": "1-konata-izumi"}
+ # # => {"id": 1, "name": "Konata Izumi", "age": 16,
+ # "created_at": "2006/08/01", "awesome": true,
+ # "permalink": "1-konata-izumi"}
#
# To include associations, use :include.
#
# konata.to_json(:include => :posts)
- #
- # {"id": 1, "name": "Konata Izumi", "age": 16,
- # "created_at": "2006/08/01", "awesome": true,
- # "posts": [{"id": 1, "author_id": 1, "title": "Welcome to the weblog"},
- # {"id": 2, author_id: 1, "title": "So I was thinking"}]}
+ # # => {"id": 1, "name": "Konata Izumi", "age": 16,
+ # "created_at": "2006/08/01", "awesome": true,
+ # "posts": [{"id": 1, "author_id": 1, "title": "Welcome to the weblog"},
+ # {"id": 2, author_id: 1, "title": "So I was thinking"}]}
#
# 2nd level and higher order associations work as well:
#
@@ -46,13 +41,12 @@ module ActiveRecord #:nodoc:
# :include => { :comments => {
# :only => :body } },
# :only => :title } })
- #
- # {"id": 1, "name": "Konata Izumi", "age": 16,
- # "created_at": "2006/08/01", "awesome": true,
- # "posts": [{"comments": [{"body": "1st post!"}, {"body": "Second!"}],
- # "title": "Welcome to the weblog"},
- # {"comments": [{"body": "Don't think too hard"}],
- # "title": "So I was thinking"}]}
+ # # => {"id": 1, "name": "Konata Izumi", "age": 16,
+ # "created_at": "2006/08/01", "awesome": true,
+ # "posts": [{"comments": [{"body": "1st post!"}, {"body": "Second!"}],
+ # "title": "Welcome to the weblog"},
+ # {"comments": [{"body": "Don't think too hard"}],
+ # "title": "So I was thinking"}]}
def to_json(options = {})
JsonSerializer.new(self, options).to_s
end