-
Notifications
You must be signed in to change notification settings - Fork 189
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
Preserve the url hash when changing locales. #2964
Conversation
e116f80
to
afd76ad
Compare
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 noticing and fixing this!
I just have two minor comments otherwise LGTM :)
var csrfToken = $('meta[name=csrf-token]').attr('content'); | ||
var csrfParam = $('meta[name=csrf-param]').attr('content'); | ||
var form = $('<form method="post" action="' + href + '"></form>'); | ||
var metadataInput = '<input name="_method" value="' + method + '" type="hidden" />'; |
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.
Can't we simply use "patch" here instead of a separate variable?
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.
Good idea! You are seeing evidence of my copy paste-ing =)
var method = "patch"; | ||
var csrfToken = $('meta[name=csrf-token]').attr('content'); | ||
var csrfParam = $('meta[name=csrf-param]').attr('content'); | ||
var form = $('<form method="post" action="' + href + '"></form>'); |
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.
href
is used only here, so you can maybe just use this.href
here and drop the variable.
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.
Good idea! You are seeing evidence of my copy paste-ing =)
To implement this, I had to write a custom javascript handler to handle switching locales. Previously, this was handled for us via Rails's unobtrusive javascript, but I could not find any way to add in additional url parameters to the PATCH request the unobtrusive javascript was generating for us. There's actually an open PR from 2013 to implement support for this here: rails/jquery-ujs#307. I also rewrote the set_locale_spec to enable javascript and be more like what I believe a feature spec should be. I actually don't understand how the spec was even passing before, I would expect it to fail because it was sending a GET request, and we don't have a handler for GET request to update the locale. Maybe rspec/capybara/poltergiest has baked in support for unobtrusive javascript so that the right thing will happen even if you don't have javascript enabled?? That sounds crazy, but it's the only thing I can think of. Regardless of how this was working before, I do believe that the new specs are better. This fixes thewca#2962.
afd76ad
to
4d913ad
Compare
To implement this, I had to write a custom javascript handler to handle
switching locales. Previously, this was handled for us via Rails's
unobtrusive javascript, but I could not find any way to add in
additional url parameters to the PATCH request the unobtrusive
javascript was generating for us. There's actually an open PR from 2013
to implement support for this here: rails/jquery-ujs#307.
I also rewrote the set_locale_spec to enable javascript and be more like
what I believe a feature spec should be. I actually don't understand how
the spec was even passing before, I would expect it to fail because it
was sending a GET request, and we don't have a handler for GET request
to update the locale. Maybe rspec/capybara/poltergiest has baked in
support for unobtrusive javascript so that the right thing will happen
even if you don't have javascript enabled?? That sounds crazy, but it's
the only thing I can think of. Regardless of how this was working
before, I do believe that the new specs are better.
This fixes #2962.