I have a class Event where I need a method that compares the current date to the date the Event was created. Can you tell me how to access the created_at timestamp the scaffold created for the Event database table?
class Event < ActiveRecord::Base
attr_accessible :location, :name
def isInsertedLongAgo
# current date - insertion date >= 90 days
end
end
Same as any other attribute - just call it:
def isInsertedLongAgo
# current date - insertion date >= 90 days
Time.now - created_at >= 90.days
end
Hi you can acces created at using created_at field self.created_at
, At the time of scaffold time stamp is created which create created_at,updated_at You can directly access those variables. replace insertion date with created_at
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.