-
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
Overriding adapter #1039
Comments
Wondering how you're able to override the adapter as shown above--any other setup required to pass
and have it change adapters? I get a NoMethodError currently when trying it that way. |
Yep, it should change adapter. When you are passing :adapter options to AMS changing a lot now, so you may be looking to not latest version. |
Hey @bolshakov, indeed, this would be an improvement. It seems an edge-case for me, but it's a valid scenario, I'll keep it open! 😄 |
Hi @joaomdmoura and @bolshakov I am thinking of tackling this issue but I am not sure which approach is better
Secondly if we allow users to pass the class name should it be name spaced under Or should we allow users to just define a class |
@mrageh, there is already something about that on https://github.com/rails-api/active_model_serializers/blob/master/lib/active_model/serializer.rb#L92, but it works only if you are not using in your action. I believe we could improve it, what do you think? About your question, I would go for defining a class instead of declare the entire path |
So do we want to pass both a class and a symbol to This is a PR I can finish today but I need guidance on how we want this api to work. So far I know that we won't require users to name space their custom serialisers thanks to @bacarini. Do we still want to substitute Thanks |
Would also be very useful to override the adapter within the serializer (i.e. not in the controller), based on scope/user properties. A common use-case is client-versioning, e.g. the mobile client < Y.x should get data serialized using the adapter-A, and newer clients should use adapter-B. Changing the adapter on-the-fly must also take caching into consideration (pretty obvious), since the output would differ. |
ref: #1017 |
@sandstrom that would be nice, but would be kind complex, I think that right now I would let ppl use conditionals inside controllers in order to render a specific @mrageh sorry for take so long to reply my last week was crazy and the next one might be as well, but I'm trying to catch up with everything right now. |
@joaomdmoura I think someone else already created a really nice PR for this issue :) |
I can override adapter for specific action this way
This is not convenient enough if you use your own adapter, since adapter string is converted to adapter class in the
ActiveModel
namespace:My suggestion is to pass adapter as a class instead of symbol, or allow to pass both class an symbol.
The text was updated successfully, but these errors were encountered: