[英]RoR: how to get the creation timestamp in the model
我有一个Event类,在其中需要一个将当前日期与Event创建日期进行比较的方法。 您能告诉我如何访问为事件数据库表创建的支架的created_at时间戳吗?
class Event < ActiveRecord::Base
attr_accessible :location, :name
def isInsertedLongAgo
# current date - insertion date >= 90 days
end
end
与其他任何属性相同-只需调用它即可:
def isInsertedLongAgo
# current date - insertion date >= 90 days
Time.now - created_at >= 90.days
end
嗨,您可以使用created_at字段self.created_at
创建的权限,在创建脚手架时创建create_at,updated_at时间戳。您可以直接访问这些变量。 用created_at替换插入日期
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.