Ruby on rails 3.2 i18n set_区域设置未注册

Ruby on rails 3.2 i18n set_区域设置未注册,ruby-on-rails-3.2,rails-i18n,Ruby On Rails 3.2,Rails I18n,rails3.2.18应用程序具有以下应用程序控制器方法 def set_locale if user_signed_in? I18n.locale = current_user.idioma.code.downcase else I18n.locale = params[:locale] || I18n.default_locale end end 查询应用程序的给定表单集: <%= form_tag @b1, url: resu

rails3.2.18应用程序具有以下应用程序控制器方法

  def set_locale
    if user_signed_in?
      I18n.locale = current_user.idioma.code.downcase
    else
      I18n.locale = params[:locale] || I18n.default_locale
    end
  end
查询应用程序的给定表单集:

<%= form_tag @b1, url: results_b1s_path, :validate => true, :method => :get do %>
[...]
<%= submit_tag (t 'submit', locale: I18n.locale.to_s) %>

具有与第一个表单标记相同的行为。

提交其参数的表单和区域设置参数之间存在潜在的逻辑冲突问题

解决这个问题的一个方法是部分地避开
参数[:locale]
,并设置一个
会话[:locale]
,这从用户的角度来看是有意义的

从下面可以看出,用户保存的语言环境胜过一切。然后,用户请求的区域设置将存储在会话中,直到另有定义。
params[:locale]
不会干扰表单params。该逻辑以前使用注释掉的行运行

  def set_locale
    if user_signed_in?
      I18n.locale = current_user.idioma.code.downcase
    else
      if !params[:locale].nil?
        session[:locale] = params[:locale]
      end
#      I18n.locale = params[:locale] || I18n.default_locale
      I18n.locale = session[:locale] || I18n.default_locale
    end
  end
  def set_locale
    if user_signed_in?
      I18n.locale = current_user.idioma.code.downcase
    else
      if !params[:locale].nil?
        session[:locale] = params[:locale]
      end
#      I18n.locale = params[:locale] || I18n.default_locale
      I18n.locale = session[:locale] || I18n.default_locale
    end
  end