Permalink
Browse files

Merge pull request #6938 from acapilleri/as_json_refactoring

Small refactoring of as_json method
  • Loading branch information...
2 parents 84b9781 + fde7fd8 commit d4f59783d22d573a2ebbd4fc66024efbb122ba98 @carlosantoniodasilva carlosantoniodasilva committed Jul 7, 2012
Showing with 6 additions and 2 deletions.
  1. +6 −2 activemodel/lib/active_model/serializers/json.rb
@@ -87,8 +87,12 @@ module JSON
# # { "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) }

0 comments on commit d4f5978

Please sign in to comment.