-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace fail/rescue CollectionSerializer::NoSerializerError with throw/catch :no_serializer #1767
Conversation
What was wrong about |
It's not a failure... B mobile phone
|
I dig it. Slightly simpler. |
@@ -6,6 +6,7 @@ Breaking changes: | |||
|
|||
Features: | |||
- [#1426](https://github.com/rails-api/active_model_serializers/pull/1426) Add ActiveModelSerializers.config.default_includes (@empact) | |||
- [TBD](TBD) Replace raising/rescuing `CollectionSerializer::NoSerializerError`, throw/catch `:no_serializer`. (@bf4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:!!!
if serializer_class.nil? # rubocop:disable Style/GuardClause | ||
fail NoSerializerError, "No serializer found for resource: #{resource.inspect}" | ||
if serializer_class.nil? | ||
ActiveModelSerializers.logger.debug "No serializer found for resource: #{resource.inspect}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it does, although we should also warn when we can't find a serializer for something that is not inside a collection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean at serializer lookup on rendered resource but on associations? Or just always debug?
B mobile phone
On Jun 9, 2016, at 4:09 AM, Lucas Hosseini notifications@github.com wrote:
In lib/active_model/serializer/collection_serializer.rb:
@@ -73,8 +72,9 @@ def serializers_from_resources
def serializer_from_resource(resource, serializer_context_class, options)
serializer_class = options.fetch(:serializer) { serializer_context_class.serializer_for(resource) }
if serializer_class.nil? # rubocop:disable Style/GuardClause
fail NoSerializerError, "No serializer found for resource: #{resource.inspect}"
if serializer_class.nil?
I think it does, although we should also warn when we can't find a serializer for something that is not inside a collection.ActiveModelSerializers.logger.debug "No serializer found for resource: #{resource.inspect}"
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
@@ -15,7 +15,7 @@ It requires an adapter to transform its attributes into a JSON document; it cann | |||
It may be useful to think of it as a | |||
[presenter](http://blog.steveklabnik.com/posts/2011-09-09-better-ruby-presenters). | |||
|
|||
The **`ActiveModel::ArraySerializer`** represent a collection of resources as serializers | |||
The **`ActiveModel::CollectionSerializer`** represent a collection of resources as serializers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/represent/represents/
c803432
to
5b6cd92
Compare
This seems fine to me. What's holding this up apart from a rebase? |
5b6cd92
to
af5adab
Compare
@NullVoxPopuli @remear issues with failing tests should be resolved/clarified by #1904 I might broke the tests or behavior here in an earlier rebase, but wasn't sure which. #1904 will make figuring that out easier :) |
…w/catch :no_serializer
af5adab
to
13fa368
Compare
LGTM |
Closes #1693
Fixes #1075