Make sure render json: ..., each_serializer: ... is working with Enumerables

If you try to render Enumerable with custom `each_serializer` then it will render with default serializer instead:

```ruby
render json: sequel_scope, each_serializer: CustomSerializer
```

This commit fixes this behaviour. Most likely fixes https://github.com/rails-api/active_model_serializers/issues/664 as well
This commit is contained in:
Andrey Chernih
2014-09-25 16:59:47 +04:00
parent 40d53aaa16
commit 90343cea4d
4 changed files with 22 additions and 2 deletions

View File

@@ -56,7 +56,7 @@ end
attr_reader :key_format
def serializer_for(resource, options = {})
if resource.respond_to?(:to_ary)
if resource.respond_to?(:each)
if Object.constants.include?(:ArraySerializer)
::ArraySerializer
else