diff options
Diffstat (limited to 'activemodel')
-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) } |