Ruby on rails Can';在Heroku中运行时,不要更改rails应用程序的区域设置,这在开发中很有效

Ruby on rails Can';在Heroku中运行时,不要更改rails应用程序的区域设置,这在开发中很有效,ruby-on-rails,internationalization,heroku,Ruby On Rails,Internationalization,Heroku,我正在开发一个双语应用程序。我可以在开发中通过?locale=en将语言环境更改为英语,它在开发中有效,但在heroku中无效 通过我在下面插入的记录器,我可以知道语言环境实际上发生了变化,但所有内容都是在默认语言环境中发出的 应用程序\u controller.rb class ApplicationController < ActionController::Base protect_from_forgery before_filter :set_locale def s

我正在开发一个双语应用程序。我可以在开发中通过?locale=en将语言环境更改为英语,它在开发中有效,但在heroku中无效

通过我在下面插入的记录器,我可以知道语言环境实际上发生了变化,但所有内容都是在默认语言环境中发出的

应用程序\u controller.rb

class ApplicationController < ActionController::Base
  protect_from_forgery
  before_filter :set_locale

  def set_locale    
    if %w(en pt-BR).include? params[:locale]
      I18n.locale = params[:locale].to_sym
    end
    logger.info I18n.locale
  end
end
试试这个

class ApplicationController < ActionController::Base
  protect_from_forgery
  before_filter :set_locale

  protected    
  def set_locale
    if params[:locale].blank?
      I18n.locale = :'pt-BR'
    else
      I18n.locale = params[:locale]
    end
  end   

  # ensure locale persists
  def default_url_options(options={})
    {:locale => I18n.locale}
  end
end
拥有
domain.tld/:locale/
类型路由也会让人感觉更干净

class ApplicationController < ActionController::Base
  protect_from_forgery
  before_filter :set_locale

  protected    
  def set_locale
    if params[:locale].blank?
      I18n.locale = :'pt-BR'
    else
      I18n.locale = params[:locale]
    end
  end   

  # ensure locale persists
  def default_url_options(options={})
    {:locale => I18n.locale}
  end
end
  scope "(:locale)", :locale => /pt-BR|en/ do
    resources :products  # update this!
  end