mirror of
https://github.com/samsonjs/grape-active_model_serializers.git
synced 2026-04-27 14:57:43 +00:00
fix: when resource is empty, keep json resource root
This commit is contained in:
parent
e30af569b2
commit
94a6122c9e
1 changed files with 2 additions and 4 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue