我有一个类事件,我需要一个方法,将当前日期与创建事件的日期进行比较。你能告诉我如何访问为事件数据库表创建的脚手架的created_at时间戳吗?
class Event < ActiveRecord::Base
attr_accessible :location, :name
def isInsertedLongAgo
# current date - insertion date >= 90 days
end
end
答案 0 :(得分:1)
与任何其他属性相同 - 只需调用它:
def isInsertedLongAgo
# current date - insertion date >= 90 days
Time.now - created_at >= 90.days
end
答案 1 :(得分:0)
您可以使用created_at字段self.created_at
创建访问权限,
在脚手架时创建时间戳,创建created_at,updated_at
您可以直接访问这些变量。
使用created_at替换插入日期