# Trying to refresh a view after changing the user language (I18n, locale)

**URL:** <https://www.ruby-forum.com/t/trying-to-refresh-a-view-after-changing-the-user-language-i18n-locale/195584>\
**Category:** Rails\
**Created:** [September 25, 2010, 11:31pm UTC](https://www.ruby-forum.com/t/trying-to-refresh-a-view-after-changing-the-user-language-i18n-locale/195584 "2010-09-25T23:31:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick\_Meyer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/848f3c/32.png) [@Patrick\_Meyer](https://www.ruby-forum.com/u/Patrick_Meyer)\
**Post date:** [September 25, 2010, 11:31pm UTC](https://www.ruby-forum.com/t/trying-to-refresh-a-view-after-changing-the-user-language-i18n-locale/195584/1 "2010-09-25T23:31:00Z")

</div>

I’m trying to build a language selector into my rails app. The  
selector is defined within the application layout and upon language  
selection the current view should be updated to the selected language.  
The selected language should then be passed to all subsequent  
requests , the url should take the following form:  
[http://localhost:300/fr/producers](http://localhost:300/fr/producers)  
where the selected locale is systematically part of the url.

I have a problem with the selector that does not automatically  
‘refresh’ the view to the selected language upon language selection.  
Can somebody help me on this one ?

Here is the relevant parts of the code:

#application\_controller.rb :  
class ApplicationController \< ActionController::Base  
protect\_from\_forgery

before\_filter :set\_locale

def set\_locale  
I18n.locale = params[:locale]  
end

def default\_url\_options(options={})  
{ :locale =\> I18n.locale }  
end  
end

#The layout application.html.erb:

 Test \<%= stylesheet\_link\_tag :all %\> \<%= javascript\_include\_tag :defaults %\> \<%= csrf\_meta\_tag %\> \<%= form\_tag '', :method =\> 'GET' do %\> \<%= select\_tag :locale, options\_for\_select(LANGUAGES, I18n.locale), :onchange =\> 'this.form.submit();' %\> \<% end %\>

\<%= yield %\>

#routes.rb:  
scope “(/:locale)” do  
resources :producers do  
collection do  
get ‘update\_regions’  
end  
end

#config/application.rb:  
config.i18n.default\_locale = :de

---

<div class="post-metadata">

**Author:** ![Patrick\_Meyer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/848f3c/32.png) [@Patrick\_Meyer](https://www.ruby-forum.com/u/Patrick_Meyer)\
**Post date:** [September 26, 2010, 1:35am UTC](https://www.ruby-forum.com/t/trying-to-refresh-a-view-after-changing-the-user-language-i18n-locale/195584/2 "2010-09-26T01:35:40Z")

</div>

set\_locale should trigger if params[:locales] exists and but it should  
refresh if you submit, are you sure is submitting?
