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

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:
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

before_filter :set_locale

def set_locale
I18n.locale = params[:locale]

def default_url_options(options={})
{ :locale => I18n.locale }

#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 %>

scope “(/:locale)” do
resources :producers do
collection do
get ‘update_regions’

config.i18n.default_locale = :de

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs