0
如何使用select_tag更改語言環境?在Rails 3應用程序中使用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 %>
在我的ApplicationController我有一個set_locale方法:
def set_locale
I18n.locale = params[:locale] if params.include?('locale') && !Language.where(:two_letter_code => params[:locale]).empty?
end
但它不工作...
謝謝。
鏈接可能是解決方案: ** 1 ** [Select Function for Internationalization API](http://stackoverflow.com/questions/13497177/how-to-use-javascript-selected-functionality-when-特定語言選擇) ** 2 ** [設置基於位置的區域設置](http://stackoverflow.com/questions/13310812/set-locale-automatically-in-ruby-on-rails) – TheMouseMan
你到底是怎麼解決這個問題的? –