Extend member_action? by checking for instance_name id #837
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently only :id and :id_param are checked for member_action?. I think it makes sense to extend it by instance_name id.
Given the following url
/authors/1/books/1
the rails route might look like
/authors/:id/books/:book_id or /authors/:author_id/books/:book_id
In these cases the member_action? will return false for either one or both controllers, since it won't find the :id param. This results in not loading the instance for actions like show/edit when using authorize_resource. The solution here is to explicity set the id_param option. But from my point of view, this id naming scheme is quite common and should be considered when checking the id param.
This PR adds an id check for instance_name + _id, which would fullfil most of these cases.