问题描述
|
最好的方法是检查日期是否超过一天或一岁等?
解决方法
看到这个问题:红宝石中的日期比较
与类似的值进行比较
1.day.ago
1.month.ago
1.year.ago
使用这些将产生以下输出:
Loading development environment (Rails 3.0.7)
ruby-1.9.2-p180 :001 > 1.year.ago
=> Thu,27 May 2010 17:45:25 UTC +00:00
ruby-1.9.2-p180 :002 > 1.month.ago
=> Wed,27 Apr 2011 17:45:32 UTC +00:00
ruby-1.9.2-p180 :003 > 1.day.ago
=> Thu,26 May 2011 17:45:36 UTC +00:00
ruby-1.9.2-p180 :004 >
看看是否可行。
, 使用ActiveSupport助手
@date < 1.day.ago
@some_other_date < 2.years.ago
, if the_date < 1.day.ago or the_date < 1.year.ago
, 尝试:
a_date > 1.day.ago
a_date > 1.year.ago