我想更改应用程序时区时,CURRENT_USER(设计)被初始化,这样的:Rails。 CURRENT_USER加载时设置默认时区
Time.zone = current_user.settings(:main).time_zone
什么是应用最好的地方,把这个代码在(应用程序控制器,before_filter不是解决方案)?
我想更改应用程序时区时,CURRENT_USER(设计)被初始化,这样的:Rails。 CURRENT_USER加载时设置默认时区
Time.zone = current_user.settings(:main).time_zone
什么是应用最好的地方,把这个代码在(应用程序控制器,before_filter不是解决方案)?
我觉得这里是最安全的方法是使用around_action像这样的,一定要指定要这个对发生的操作:
class SomeController < ApplicationController
around_action :set_time_zone, only: :show
private
def set_time_zone
if current_user
Time.zone = current_user.settings(:main).time_zone
end
yield
end
end
为什么''ApplicationController''是不是一个解决方案?这将是我的建议... – dgilperez 2015-02-11 13:53:01
Aggree与@dgilperez。 'ApplicationController'''before_filter'是解决方案。 – pierallard 2015-02-11 14:27:11
我不相信更改应用程序时区是正确的方法。如果用户更改时区怎么办? (或者它改变了夏令时? – 2015-02-11 15:28:39