diff options
author | Jatinder Singh <jatinder.saundh@gmail.com> | 2010-04-30 21:02:11 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2010-05-04 13:17:26 -0700 |
commit | bce2c0ce37cbd4abb45ca36362fbb8fae3bbc6b9 (patch) | |
tree | 48f360dd477b96d1a9816c529971268575f62e18 /activemodel/lib | |
parent | 7aad851c2e0d4579aa33a54a069a767b53cca406 (diff) | |
download | rails-bce2c0ce37cbd4abb45ca36362fbb8fae3bbc6b9.tar.gz rails-bce2c0ce37cbd4abb45ca36362fbb8fae3bbc6b9.tar.bz2 rails-bce2c0ce37cbd4abb45ca36362fbb8fae3bbc6b9.zip |
Active Model JSON serializer now supports custom root option
[#4515 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activemodel/lib')
-rw-r--r-- | activemodel/lib/active_model/serializers/json.rb | 6 |
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 |