fix: when resource is empty, keep json resource root

This commit is contained in:
Stephane Bounmy 2014-07-06 00:12:41 +02:00
parent e30af569b2
commit 94a6122c9e

View file

@ -18,10 +18,8 @@ module Grape
if serializer = options.fetch(:serializer, ActiveModel::Serializer.serializer_for(resource)) if serializer = options.fetch(:serializer, ActiveModel::Serializer.serializer_for(resource))
options[:scope] = serialization_scope unless options.has_key?(:scope) options[:scope] = serialization_scope unless options.has_key?(:scope)
if resource.respond_to?(:to_ary) && !resource.empty? # ensure we have an root to fallback on
# ensure we have an root to fallback on options[:resource_name] = default_root(endpoint) if resource.respond_to?(:to_ary)
options[:resource_name] = default_root(endpoint)
end
serializer.new(resource, options.merge(other_options)) serializer.new(resource, options.merge(other_options))
end end
end end