diff options
author | Dmitry Polushkin <dmitry.polushkin@gmail.com> | 2011-10-01 20:49:14 +0100 |
---|---|---|
committer | Dmitry Polushkin <dmitry.polushkin@gmail.com> | 2011-10-01 20:49:14 +0100 |
commit | 19965402b2f868c79d78269ca17cb6282f271382 (patch) | |
tree | 8635415f386595650c27469d6b6d04335121d070 /activemodel/lib/active_model/serializers/json.rb | |
parent | 9d54f8994d09db5435d6c234430ae13333928fb9 (diff) | |
parent | ec53b802dab9b676dcc9b53e542bcd840983b7a2 (diff) | |
download | rails-19965402b2f868c79d78269ca17cb6282f271382.tar.gz rails-19965402b2f868c79d78269ca17cb6282f271382.tar.bz2 rails-19965402b2f868c79d78269ca17cb6282f271382.zip |
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'activemodel/lib/active_model/serializers/json.rb')
-rw-r--r-- | activemodel/lib/active_model/serializers/json.rb | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/activemodel/lib/active_model/serializers/json.rb b/activemodel/lib/active_model/serializers/json.rb index 4fbccd7419..885964633f 100644 --- a/activemodel/lib/active_model/serializers/json.rb +++ b/activemodel/lib/active_model/serializers/json.rb @@ -86,21 +86,15 @@ module ActiveModel # "title": "Welcome to the weblog"}, # {"comments": [{"body": "Don't think too hard"}], # "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] + root = include_root_in_json + root = options[:root] if options.try(:key?, :root) + if root + root = self.class.model_name.element if root == true + { root => serializable_hash(options) } + else + serializable_hash(options) end - - if include_root - custom_root = options && options[:root] - hash = { custom_root || self.class.model_name.element => hash } - end - - hash end def from_json(json, include_root=include_root_in_json) |