From f5836543c3cd16f7789c936a4181f4a7204141dc Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 28 Sep 2011 17:05:03 +0530 Subject: minor edits in serializers guide --- railties/guides/source/serializers.textile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/serializers.textile b/railties/guides/source/serializers.textile index a631a14694..86a5e5ac8d 100644 --- a/railties/guides/source/serializers.textile +++ b/railties/guides/source/serializers.textile @@ -153,9 +153,9 @@ class PostSerializerTest < ActiveSupport::TestCase json = PostSerializer.new(post, god).to_json hash = JSON.parse(json) - assert_equal post.title, hash["title"] - assert_equal post.body, hash["body"] - assert_equal post.email, hash["email"] + assert_equal post.title, hash.delete("title") + assert_equal post.body, hash.delete("body") + assert_equal post.email, hash.delete("email") assert_empty hash end end @@ -255,7 +255,7 @@ the comments with the current post. class PostSerializer < ActiveModel::Serializer - attributes :title. :body + attributes :title, :body has_many :comments private @@ -361,7 +361,7 @@ build up the hash manually. For example, let's say our front-end expects the posts and comments in the following format: - + { post: { id: 1 @@ -382,7 +382,7 @@ For example, let's say our front-end expects the posts and comments in the follo } ] } - + We could achieve this with a custom +as_json+ method. We will also need to define a serializer for comments. @@ -394,7 +394,7 @@ class CommentSerializer < ActiveModel::Serializer end class PostSerializer < ActiveModel::Serializer - attributes :title. :body + attributes :title, :body has_many :comments def as_json @@ -558,7 +558,7 @@ as the root). For example, an Array of post objects would serialize as: - + { posts: [ { @@ -570,7 +570,7 @@ For example, an Array of post objects would serialize as: } ] } - + If you want to change the behavior of serialized Arrays, you need to create a custom Array serializer. -- cgit v1.2.3