[英]How to make “edit post” method available for only 10 minutes in Rails?
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. 我正在将Instagram克隆作为一个迷你项目,以了解如何使用Rails,我之前没有任何经验。 One of the "client" requirements is to be able to edit their comments on a post but only for up to 15 minutes.
“客户”要求之一是能够编辑他们对帖子的评论,但最多只能持续15分钟。
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?
Rails中有什么可以帮助我做到这一点的吗?
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.