0

How could I change locale with a select_tag?

    <%= form_tag ({:action => "set_locale"}) do %>
        <%= select_tag "select_lang", options_from_collection_for_select(@languages, "two_letter_code", "name") %>
        <%= submit_tag("set language") %>
    <% end %>

In my applicationController I have a set_locale method:

def set_locale
    I18n.locale = params[:locale] if params.include?('locale') && !Language.where(:two_letter_code => params[:locale]).empty?
end

But it doesnt works...

thank you.

user1364684
  • 800
  • 2
  • 8
  • 28
  • The links may be the solutions: **1** [Select Function for Internationalisation API](http://stackoverflow.com/questions/13497177/how-to-use-javascript-selected-functionality-when-particular-language-is-selecte) **2** [Set Locale Based on Location](http://stackoverflow.com/questions/13310812/set-locale-automatically-in-ruby-on-rails) – RajG Jan 11 '13 at 11:26
  • How did you solve this in the end? – Tasos Anesiadis Jul 21 '16 at 09:27

1 Answers1

0

I think your problem is the parameter is a string ("en") instead of a symbol (:en). params[:locale].to_sym might help.

Hugo Logmans
  • 2,202
  • 1
  • 19
  • 14