From 94a6122c9e3ddd3066e7bb652cd420e90be27a45 Mon Sep 17 00:00:00 2001 From: Stephane Bounmy Date: Sun, 6 Jul 2014 00:12:41 +0200 Subject: [PATCH] fix: when resource is empty, keep json resource root --- lib/grape-active_model_serializers/formatter.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/grape-active_model_serializers/formatter.rb b/lib/grape-active_model_serializers/formatter.rb index 49b3c19..4dc28d3 100644 --- a/lib/grape-active_model_serializers/formatter.rb +++ b/lib/grape-active_model_serializers/formatter.rb @@ -18,10 +18,8 @@ module Grape if serializer = options.fetch(:serializer, ActiveModel::Serializer.serializer_for(resource)) 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 - options[:resource_name] = default_root(endpoint) - end + # ensure we have an root to fallback on + options[:resource_name] = default_root(endpoint) if resource.respond_to?(:to_ary) serializer.new(resource, options.merge(other_options)) end end