aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2011-09-28 17:05:03 +0530
committerJose and Yehuda <wycats@gmail.com>2011-10-15 18:40:37 +0200
commitf5836543c3cd16f7789c936a4181f4a7204141dc (patch)
treee0415a706c0c1860ec6495a5b93bf73b533e397c /railties/guides
parentc3de52d7ed470433e9ecd44226518797c0a9f389 (diff)
downloadrails-f5836543c3cd16f7789c936a4181f4a7204141dc.tar.gz
rails-f5836543c3cd16f7789c936a4181f4a7204141dc.tar.bz2
rails-f5836543c3cd16f7789c936a4181f4a7204141dc.zip
minor edits in serializers guide
Diffstat (limited to 'railties/guides')
-rw-r--r--railties/guides/source/serializers.textile18
1 files changed, 9 insertions, 9 deletions
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.
<ruby>
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:
-<javascript>
+<plain>
{
post: {
id: 1
@@ -382,7 +382,7 @@ For example, let's say our front-end expects the posts and comments in the follo
}
]
}
-</javascript>
+</plain>
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:
-<javascript>
+<plain>
{
posts: [
{
@@ -570,7 +570,7 @@ For example, an Array of post objects would serialize as:
}
]
}
-</javascript>
+</plain>
If you want to change the behavior of serialized Arrays, you need to create
a custom Array serializer.