diff options
author | Angelo Capilleri <capilleri@yahoo.com> | 2012-07-03 08:38:02 +0200 |
---|---|---|
committer | Angelo Capilleri <capilleri@yahoo.com> | 2012-07-03 15:11:41 +0200 |
commit | fde7fd8693c30e40675000f001cac40016014e84 (patch) | |
tree | fb7b0f845220ee3033574ed1897ccb3a7239af4a | |
parent | 55456ad34ac2be56392bce074577ebc0aeb509b2 (diff) | |
download | rails-fde7fd8693c30e40675000f001cac40016014e84.tar.gz rails-fde7fd8693c30e40675000f001cac40016014e84.tar.bz2 rails-fde7fd8693c30e40675000f001cac40016014e84.zip |
small refactoring of as_json method
with this change root has always one assignment
-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) } |