我想获取未登录用户的时区。然后将帖子的created_at时间转换为该时区?
我搜索了网络,但我没有收到任何与访客用户的时区相关的帖子。
在我的application.rb文件中,我将时区设置为:
config.time_zone = 'Central Time (US & Canada)'
答案 0 :(得分:0)
我假设你已经在任何对象中拥有guest_user,实际使用该用户的时区最常见的模式是在ActionController中创建一个私有方法并将其作为around过滤器运行。
around_filter :user_time_zone, :if => :guest_user
def user_time_zone(&block)
Time.use_zone(guest_user.time_zone, &block)
end
希望这会有所帮助。感谢