ruby-on-rails – TimeZone的参数无效?
发布时间:2020-12-17 03:22:12 所属栏目:百科 来源:网络整理
导读:我正在尝试让我的用户时区成为我的应用程序的当前时区,所以他们互动的一切都将由它完成.我在ApplicationController中遇到了我的方法的ArgumentError. application_controller.rb before_filter :set_user_time_zoneprivatedef set_user_time_zone if signed_
我正在尝试让我的用户时区成为我的应用程序的当前时区,所以他们互动的一切都将由它完成.我在ApplicationController中遇到了我的方法的ArgumentError.
application_controller.rb before_filter :set_user_time_zone private def set_user_time_zone if signed_in? Time.zone = Time.now.in_time_zone(current_user.time_zone) end end 注意:current_user是一个Devise Helper,我的用户模型是:time_zone列. 比错误: invalid argument to TimeZone[]: Mon,20 Aug 2012 13:16:20 JST +09:00 我不知道从哪里开始.有关如何纠正此问题的任何想法? 谢谢. UPDATE class Price attr_accessible :date def self.today where(:date => Date.today) end end 如果我的方法: def set_user_time_zone if signed_in? Time.zone = current_user.time_zone end end 我有我的时代的问题是这样的: Time.now = US EAST- 2012-08-22 21:17:03 -0400 Time.zone = TOKYO - (GMT+09:00) Tokyo Time.zone.now 2012-08-23 10:17:03 +0900 这意味着我的所有Date方法都会消失 Time.now = US EAST- 2012-08-22 21:17:03 -0400 什么时候应该 Time.zone.now 2012-08-23 10:17:03 +0900 怎么才能把它送到后者? 解决方法
Time.now.in_time_zone(current_user.time_zone)返回TimeWithZone类的实例,但是
Time#zone =期望获得可以转换为TimeZone的内容. 假设您将TimeZone标识符存储在:time_zone列(“东部时间(美国和加拿大)”,“夏威夷”等)中,您可以简单地执行此操作 Time.zone = current_user.time_zone (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |