Patrick Meyer
2010-Sep-25 17:20 UTC
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:
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:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
</head>
<body>
<%= form_tag '''', :method => ''GET'' do
%>
<%= select_tag :locale, options_for_select(LANGUAGES,
I18n.locale), :onchange => ''this.form.submit();'' %>
<% end %>
<%= yield %>
</body>
</html>
#routes.rb:
scope "(/:locale)" do
resources :producers do
collection do
get ''update_regions''
end
end
#config/application.rb:
config.i18n.default_locale = :de
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Sep-25 23:34 UTC
Re: Trying to refresh a view after changing the user language (I18n, locale)
set_locale should trigger if params[:locales] exists and but it should refresh if you submit, are you sure is submitting? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.