加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – 未定义的方法`zone` for Time:Class,需要active_suppor

发布时间:2020-12-17 04:22:50 所属栏目:百科 来源:网络整理
导读:我在 Ruby 2.2.1上安装了active_support 4.2,所以我想使用它 Time.zone.parse('2007-02-10 15:30:45') 如下所述:http://api.rubyonrails.org/classes/ActiveSupport/TimeWithZone.html 但即使在需要active_support和active_support / time_with_zone之后,我
我在 Ruby 2.2.1上安装了active_support 4.2,所以我想使用它
Time.zone.parse('2007-02-10 15:30:45')

如下所述:http://api.rubyonrails.org/classes/ActiveSupport/TimeWithZone.html

但即使在需要active_support和active_support / time_with_zone之后,我似乎仍然无法使用Time.zone.注意:

2.2.1 :002 >   require "active_support"
 => true
2.2.1 :003 > Time.zone
NoMethodError: undefined method `zone' for Time:Class
2.2.1 :004 > require "active_support/time_with_zone"
 => true
2.2.1 :005 > Time.zone
NoMethodError: undefined method `zone' for Time:Class

这是怎么回事?

解决方法

Time类的zone类方法实际上位于active_support / core_ext / time / zones中.如果您真的想使用Time.zone,则可以要求该类,但更好的方法可能需要active_support / all

建议的解决方案

require "active_support/all"

如果你想查看active_support的源代码堡,请查看github repo

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读