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
Fix URL generation when explicitly passing params to link helpers #874
Fix URL generation when explicitly passing params to link helpers #874
Conversation
@@ -24,7 +24,7 @@ def initialize(template, params: {}, param_name: nil, theme: nil, views_prefix: | |||
@params = @params.to_unsafe_h if @params.respond_to?(:to_unsafe_h) | |||
@params = @params.with_indifferent_access | |||
@params.except!(*PARAM_KEY_BLACKLIST) | |||
@params.merge! params | |||
@params.reverse_merge! params |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 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,
params
may have nestedActionController::Parameters
.Although Kaminari converts
ActionController::Parameters
toHash
in initializer ofKaminari::Helpers::Tag
in order to pass it tourl_for
helper for URL generation,ActionController::Parameters
in explicitly passedparams
remain 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_for
helper seems to have been improved to takeActionController::Parameters
as an argument. I am not sure if Kaminiari requires additional changes for Rails' changes.