diff --git a/lib/grape-active_model_serializers/serializer_resolver.rb b/lib/grape-active_model_serializers/serializer_resolver.rb index b9949e3..13220a1 100644 --- a/lib/grape-active_model_serializers/serializer_resolver.rb +++ b/lib/grape-active_model_serializers/serializer_resolver.rb @@ -48,8 +48,9 @@ def resource_defined_class end def collection_class - return nil unless resource.respond_to?(:to_ary) - ActiveModel::Serializer.config.collection_serializer + if resource.respond_to?(:to_ary) || resource.respond_to?(:all) + ActiveModel::Serializer.config.collection_serializer + end end def namespace_inferred_class @@ -84,8 +85,10 @@ def resource_namespace end def resource_class - if resource.respond_to?(:to_ary) - resource.try(:klass) || resource.compact.first.class + if resource.respond_to?(:klass) + resource.klass + elsif resource.respond_to?(:to_ary) || resource.respond_to?(:all) + resource.first.class else resource.class end