我有一個記錄日期時間屬性:爲什麼日期助手不能在Rails控制檯中工作?
1.9.3p194 :024> f.last_contact
=> Thu, 11 Aug 2011 00:00:00 UTC +00:00
但是當我嘗試time_ago_in_words
在控制檯上,這是行不通的:
> time_ago_in_words(f.last_contact)
NoMethodError: undefined method `time_ago_in_words' for main:Object
我也試過distance_of_time_in_words
該文檔說應該工作與Time, Date & DateTime objects。
> to_time = Time.now
=> 2012-09-08 12:22:16 -0500
> distance_of_time_in_words(f.last_contact, to_time)
NoMethodError: undefined method `distance_of_time_in_words' for main:Object
這是什麼原因?不應該Rails控制檯加載所有Rails方法的所有必要的庫和依賴項的工作?
完美!謝謝。 – marcamillion
一百萬+1 – thedanotto