aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activemodel/lib/active_model/serializers/json.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/activemodel/lib/active_model/serializers/json.rb b/activemodel/lib/active_model/serializers/json.rb
index f77fb98c32..09dcae889b 100644
--- a/activemodel/lib/active_model/serializers/json.rb
+++ b/activemodel/lib/active_model/serializers/json.rb
@@ -42,6 +42,13 @@ module ActiveModel
# # => { "user" => { "id" => 1, "name" => "Konata Izumi", "age" => 16,
# # "created_at" => "2006-08-01T17:27:13.000Z", "awesome" => true } }
#
+ # If you prefer, <tt>:root</tt> may also be set to a custom string key instead as in:
+ #
+ # user = User.find(1)
+ # user.as_json(root: "author")
+ # # => { "author" => { "id" => 1, "name" => "Konata Izumi", "age" => 16,
+ # # "created_at" => "2006-08-01T17:27:13.000Z", "awesome" => true } }
+ #
# Without any +options+, the returned Hash will include all the model's
# attributes.
#