Fix URL generation when explicitly passing params to link helpers#874
Conversation
| @params = @params.with_indifferent_access | ||
| @params.except!(*PARAM_KEY_BLACKLIST) | ||
| @params.merge! params | ||
| @params.reverse_merge! params |
There was a problem hiding this comment.
This would slightly change the behavior - the expected behavior is that if both template.params and params (the argument of this method) have the same key, the one in the argument params should take the precedence.
There was a problem hiding this comment.
Thanks for your review. Ah true, in the real use-cases you expect that params in the argument should take the precedence.
Then what if params in the argument is converted to Hash in the same way with teamplate.params ?
If it looks good to you, let me confirm if it works.
There was a problem hiding this comment.
👍 on converting params to a raw hash object.
Also, as you mentioned earlier, this only occurs with unintended usage, and I wouldn't feel comfortable maintaining this bit of code forever (less code can do the same as more code). It should show a warning to inform that param: params could be removed.
|
I'm not sure whether or not there is a case where you'd have to pass in an
Hopefully @amatsuda will take care of this before Rails 5.1 comes out. |
|
I don't have any idea where you have got no choice but to pass As I described in this comment, maybe this issue occurs only with unintended usage of an API, and I was able to fix my app's codes somehow to avoid that. So I am just not sure if you regard this issue as a kind of regression because, in StackOverflow, some blogs, etc., there are quite a few example codes that passing |
|
I'm sorry for not getting back to you sooner. I think we should merge this in. Would you mind updating this PR if you are still interested? |
1bb3dbd to
900f967
Compare
|
@yuki24 I've updated this PR for:
However, I am atill a bit worried if |
|
Thanks for the request! also was great meeting you at the RubyKaigi 👍🏻 |
This resolves #873
As I described in this comment,
paramsmay have nestedActionController::Parameters.Although Kaminari converts
ActionController::ParameterstoHashin initializer ofKaminari::Helpers::Tagin order to pass it tourl_forhelper for URL generation,ActionController::Parametersin explicitly passedparamsremain as it was becausemerge!won't replace other hash's values if keys are already exist.So, I have simply changed
merge!toreverse_merge!to have an expected result. How does this sound to you?In addition to that, on the edge Rails
url_forhelper seems to have been improved to takeActionController::Parametersas an argument. I am not sure if Kaminiari requires additional changes for Rails' changes.