diff options
author | Gannon McGibbon <gannon.mcgibbon@gmail.com> | 2019-05-13 12:06:49 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-13 12:06:49 -0400 |
commit | 93ef75615e9aec522ee7478689fc6a6ed420814d (patch) | |
tree | d9be91b8afd2bd490051dab9efb17d2ad8692f6b /activemodel | |
parent | 3b2ba908bad6962be8b1b0c368a97721dc864eb4 (diff) | |
parent | 42a3ec8fee56f0dd472112796fe1ed1f31091a7a (diff) | |
download | rails-93ef75615e9aec522ee7478689fc6a6ed420814d.tar.gz rails-93ef75615e9aec522ee7478689fc6a6ed420814d.tar.bz2 rails-93ef75615e9aec522ee7478689fc6a6ed420814d.zip |
Merge pull request #36092 from imechemi/update-doc
Improve doc for :root option in as_json()
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/serializers/json.rb | 7 |
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. # |