From 42a3ec8fee56f0dd472112796fe1ed1f31091a7a Mon Sep 17 00:00:00 2001 From: Tenzin Chemi Date: Thu, 25 Apr 2019 18:23:27 +0530 Subject: Improve doc for :root option in as_json() [ci skip] Remove trailing whitespace [ci skip] Reword Root value should be string [ci skip] --- activemodel/lib/active_model/serializers/json.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activemodel') 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, :root 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. # -- cgit v1.2.3