Rails: How should Phusion Passenger and I18n.locale behave?

只谈情不闲聊 提交于 2020-01-24 09:33:21

问题


I have a Rails 2.2 web app running on Passenger / REE

I set the default locale in config/environment.rb

config.i18n.default_locale = 'en-GB'

The first request seems to have no locale set in I18n.locale

If I the visit a page with a before_filter that sets I18n.locale every subsequent visit to any controller even if it doesn't have that same before_filter setting the I18n.locale get an I18n.locale of whatever was set, say, en-US.

On Mongrel with the same code each request gets a locale of en-GB, the default, until explicitly set by a before_filter.

Any help appreciated working out if this is normal Passenger behaviour.


回答1:


Mongrel resets the locale "automatically" because it handles almost every request with a different thread, while Phusion Passenger handles everything with the same thread.

As a hack to this, in your before filter, you can always set the locale to nil before setting the locale based on other parameters. This way it will always reset the last value the locale was set to back to nil.

Just insure that you're setting the locale on each request for the user's preferred locale.

I had this same problem because I was only setting the locale if an incoming parameter told the site to change the locale. I guess this is something that you always have to set regardless if you're using Phusion Passenger.



来源:https://stackoverflow.com/questions/559382/rails-how-should-phusion-passenger-and-i18n-locale-behave

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!