-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add controller lookup. #1265
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
Add controller lookup. #1265
Conversation
Nice!! I'm really looking forward to this. 'automatic' api versioning will be a huge help to a lot of people. |
@@ -41,7 +41,7 @@ def serializer | |||
@serializer ||= | |||
begin | |||
@serializer = serializer_opts.delete(:serializer) | |||
@serializer ||= ActiveModel::Serializer.serializer_for(resource) | |||
@serializer ||= ActiveModel::Serializer.serializer_for(resource, serializer_opts.slice(:_controller_class_name)) |
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 passing the controller name to serializer_for seems weird. Would just passing the namespace make more sense? so that way you don't need to deconstantize that later?
So, is the controller being used as a serializer lookup hint? If so, I'd rather allow people to add 'hints' (I think this is was Grape calls them). I think passing the controller class all the way through AMS has pretty low value, since it adds a lot of noise for what could be resolved by specifying the class name. I'd rather work on the JSON API unless there's a lot of pressure for something like this. |
@bf4 Agreed, I made this PR because I knew how to do it without much effort, but it's not among the top priority stuff. |
Yeah, def something to figure out, maybe with a serializer version param or namespace param (which could be derived from controller or specufied) |
Yeah, as controllers mirror resource routes, i agree serializers should reflect those paths... Let's look at how other libs do it |
Do you know of other libs that do this? I think other than how the namespace (re: not the namespace, but the controller class) is passed to the serializable resource, the implementation is pretty good. |
needs rebase |
@NullVoxPopuli I'll eventually rebase this if we end up deciding to include it. Currently, it is more meant as a proof of concept than anything else. |
Well, my vote is for including it :-) |
fair enough :-) |
I would prefer a way to pass in an api version... I feel like the lookup ( |
there are many ways to handle api versioning. Some people like to have it namespaced in their routes, others like to have the version specified in a header. We may need to support both. |
@beauby yeah, I pasted the wrong link.. edited comment above to refer to #1289 (comment) |
Should this PR still be open? |
Will this get merged? Or is there something else taking its place? |
@elfassy This PR will probably not get merged, as it was meant as a proof of concept and much has changed in the meantime. I still think the feature would be useful, and would support a PR doing this in a clean way, or maybe issue one myself when I have a bit of free time. |
Closing in favor of #1436. |
This PR adds the controller's namespace to the lookup chain, such that the following works: