Use controller name as root when serializing an array and not root is defined

This commit is contained in:
Santiago Pastorino
2013-09-15 13:39:32 -03:00
parent 86b9d5a226
commit aa23e811cc
3 changed files with 18 additions and 0 deletions

View File

@@ -71,6 +71,7 @@ module ActionController
return unless serializer
options[:scope] = serialization_scope unless options.has_key?(:scope)
options[:resource_name] = self.controller_name if resource.respond_to?(:to_ary)
serializer.new(resource, options)
end

View File

@@ -16,6 +16,7 @@ module ActiveModel
@object = object
@root = options[:root]
@root = self.class._root if @root.nil?
@root = options[:resource_name] if @root.nil?
@meta_key = options[:meta_key] || :meta
@meta = options[@meta_key]
@each_serializer = options[:each_serializer]