aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/serializers
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-05-09 11:46:45 +0200
committerXavier Noria <fxn@hashref.com>2010-05-09 11:46:45 +0200
commite1a0d86fe0355ddff8c86db0f42f3824ffe14c02 (patch)
tree5833022ca41905f243c15c8a5ffdf864de69bfa6 /activemodel/lib/active_model/serializers
parent1ff3d951e620ddeeb97e87e2024391470e886467 (diff)
parentdf508bd97062b871fe25eda8d1bb61cd43d79bc4 (diff)
downloadrails-e1a0d86fe0355ddff8c86db0f42f3824ffe14c02.tar.gz
rails-e1a0d86fe0355ddff8c86db0f42f3824ffe14c02.tar.bz2
rails-e1a0d86fe0355ddff8c86db0f42f3824ffe14c02.zip
Merge remote branch 'rails/master'
Diffstat (limited to 'activemodel/lib/active_model/serializers')
-rw-r--r--activemodel/lib/active_model/serializers/json.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/serializers/json.rb b/activemodel/lib/active_model/serializers/json.rb
index 794de7dc55..ffdfbfcaaf 100644
--- a/activemodel/lib/active_model/serializers/json.rb
+++ b/activemodel/lib/active_model/serializers/json.rb
@@ -79,7 +79,11 @@ module ActiveModel
# "title": "So I was thinking"}]}
def encode_json(encoder)
hash = serializable_hash(encoder.options)
- hash = { self.class.model_name.element => hash } if include_root_in_json
+ if include_root_in_json
+ custom_root = encoder.options && encoder.options[:root]
+ hash = { custom_root || self.class.model_name.element => hash }
+ end
+
ActiveSupport::JSON.encode(hash)
end