diff options
author | Matt Aimonetti <mattaimonetti@gmail.com> | 2011-09-22 14:05:25 -0700 |
---|---|---|
committer | Matt Aimonetti <mattaimonetti@gmail.com> | 2011-09-22 14:05:25 -0700 |
commit | 6e78bbea90f744fb7de3bc93752d1519503a370d (patch) | |
tree | 35d9da3b1a7bd4ce9bda148ecd04bad8c5841cfa /activemodel/lib | |
parent | 8aa537c9452d40aeaf25e6d7e0c5bb1205b05d1a (diff) | |
download | rails-6e78bbea90f744fb7de3bc93752d1519503a370d.tar.gz rails-6e78bbea90f744fb7de3bc93752d1519503a370d.tar.bz2 rails-6e78bbea90f744fb7de3bc93752d1519503a370d.zip |
fixed a bug with the json serialization when the class setting is set to not include the root, but an instance is serialized with the root option passed as true
Diffstat (limited to 'activemodel/lib')
-rw-r--r-- | activemodel/lib/active_model/serializers/json.rb | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/activemodel/lib/active_model/serializers/json.rb b/activemodel/lib/active_model/serializers/json.rb index 4fbccd7419..3c713311fd 100644 --- a/activemodel/lib/active_model/serializers/json.rb +++ b/activemodel/lib/active_model/serializers/json.rb @@ -88,19 +88,17 @@ module ActiveModel # "title": "So I was thinking"}]} def as_json(options = nil) - hash = serializable_hash(options) - - include_root = include_root_in_json - if options.try(:key?, :root) - include_root = options[:root] - end - - if include_root - custom_root = options && options[:root] - hash = { custom_root || self.class.model_name.element => hash } + opts_root = options[:root] if options.try(:key?, :root) + if opts_root + custom_root = opts_root == true ? self.class.model_name.element : opts_root + { custom_root => serializable_hash(options) } + elsif opts_root == false + serializable_hash(options) + elsif include_root_in_json + { self.class.model_name.element => serializable_hash(options) } + else + serializable_hash(options) end - - hash end def from_json(json, include_root=include_root_in_json) |