I am making a Instagram clone as a mini project to understand how to use Rails, which I haven't had any prior experience with. One of the "client" requirements is to be able to edit their comments on a post but only for up to 15 minutes.
I have done some research but am struggling to find the best way of implementing this feature. Is there something in Rails that would help me to do this?
Thanks :)
I would use a method to check if it's editable such as:
def editable?
Time.now - self.created_at < 10.minutes
end
It needs validation as well:
def validate_is_editable
if self.persisted? && !self.editable?
self.errors[:editable] << "can edit in just 10 minutes after creation"
end
end
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.