I’ve just gone through the challenge of working out what was wrong with the following piece of code:
<% form_tag :controller => '/' do %>
<%= t(:'txt.language') %> <%= select_tag("locale", options_for_select(LOCALES_AVAILABLE, I18n.locale), { :index => nil,
nchange => 'this.form.submit()'}) %>
<% end %>
Our client reported that on a signup page where they choose an alternative language it got redirected and they could never reach the page in their native language.
How can this happen you might ask?
Well the request includes some values within the url which are used as a key. Only if the key is valid is the controller allowed to complete the request. The issue is the combining of maintaining the key and switching the language.
As it happens its a very simple fix and was pointed out to me by Juliana.
<% form_tag :controller => request.request_uri do %>
<%= t(:'txt.language') %> <%= select_tag("locale", options_for_select(LOCALES_AVAILABLE, I18n.locale), { :index => nil,
nchange => 'this.form.submit()'}) %>
<% end %>
In this fixed second example the alteration for the controller has been updated to direct the language selector to the controller of the current page. The documentation for this suggests that its broken on IIS (really should you be even trying to use this?) in fact I found that the source has had a significant amount of work go into it to work around the issue and even make it work on that webserver. Its a great little solution to ensure that the reloaded page is returned to the user in the state it was with the addition of the correct language.
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.