2013-04-18 55 views
1
require 'date' 
now = DateTime.now 
sunday = now - now.wday 

>> sunday = now - now.wday 
=> #<DateTime: 53058180361250947/21600000000,-5/24,2299161> 

由于sundayDateTime对象,我应该能够调用其实例方法如to_datemidnight,这两者的R​​ails文档中列出。为什么没有任何实例方法在DateTime对象上工作?

然而,这是我所得到的

>> sunday.to_time 
NoMethodError: undefined method `to_time' for #<DateTime: 53058180361250947/21600000000,-5/24,2299161> 
     from (irb):17 

其实没有这些实例的方法进行这项工作。我使用的是irb模式,我不知道发生了什么。任何人都可以告诉我如何解决这个问题?

回答

0

更改第一行:

require 'active_support/time' 
相关问题