Given that I have article.created_at value, I’d like to allow user to edit the article only if created_at is less than 7 days ago. If it was created_at more than 7 days ago, I do not want to let user to edit the article.
I tried using
DateTime.now.to_i - article.created_at.to_i
but it only shows time difference between them in seconds. Of course, I can use seconds to calculate 7 days, but I’d like to know if there is a better way doing this.
Thanks!
Create a method in your Article model to test from the controller that does something like this:
Then back in the controller or a view: