diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-07-07 06:39:56 -0700 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-07-07 06:39:56 -0700 |
commit | d4f59783d22d573a2ebbd4fc66024efbb122ba98 (patch) | |
tree | 4032e534ca17692c6875dd10d374c668e0409d62 /activemodel/lib/active_model | |
parent | 84b97813f687d1ed4b283e4f579ef6965988a2f6 (diff) | |
parent | fde7fd8693c30e40675000f001cac40016014e84 (diff) | |
download | rails-d4f59783d22d573a2ebbd4fc66024efbb122ba98.tar.gz rails-d4f59783d22d573a2ebbd4fc66024efbb122ba98.tar.bz2 rails-d4f59783d22d573a2ebbd4fc66024efbb122ba98.zip |
Merge pull request #6938 from acapilleri/as_json_refactoring
Small refactoring of as_json method
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r-- | activemodel/lib/active_model/serializers/json.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/serializers/json.rb b/activemodel/lib/active_model/serializers/json.rb index b4baf3a946..e4c7553cb8 100644 --- a/activemodel/lib/active_model/serializers/json.rb +++ b/activemodel/lib/active_model/serializers/json.rb @@ -87,8 +87,12 @@ module ActiveModel # # { "comments" => [ { "body" => "Don't think too hard" } ], # # "title" => "So I was thinking" } ] } def as_json(options = nil) - root = include_root_in_json - root = options[:root] if options.try(:key?, :root) + root = if options && options.key?(:root) + options[:root] + else + include_root_in_json + end + if root root = self.class.model_name.element if root == true { root => serializable_hash(options) } |