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
你到底是怎么解决这个问题的? –