-
Notifications
You must be signed in to change notification settings - Fork 530
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
Extracting the loading of source and related resources in controller actions #108
Comments
@barelyknown would it be possible for you to use the If that doesn't work for you I'm not at all opposed to splitting up the controller methods as you proposed. It could DRY it up a bit either way. |
I'm using the same approach, but that doesn't work for the |
Good catch! In |
I was tired last night too!, but I thought about it more this morning and liked your suggestion. The PR implements that approach. |
I'd like to ensure that a user is authorized to view a related resource before it is rendered, but there's no way currently without completely reimplementing the
get_related_resource
method.Here's the current implementation of
get_related_resource
inJSONAPI::ResourceController
:Ideally, we would extract two methods that could be overridden without needing to completely reimplement this method. Something like:
With these methods extracted, users of the library would have the option of authorizing the source and related resources before they're rendered. Something like:
I could also imagine handling this requirement by adding a new callback (
before_render
maybe?). But I think that I prefer the method that I mentioned above.For what it's worth, a similar problem exists with other controller actions too (some can be handled with the existing callbacks, some can't). We should use similar approaches for each action.
I'd be happy to write a PR for this tomorrow, but I wanted to discuss this issue and approach before adding the feature.
The text was updated successfully, but these errors were encountered: