forked from makersacademy/acebook-rails-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Working with time in Ruby
Melvin Lau edited this page Nov 8, 2019
·
3 revisions
Useful website to choose your format and get the required string: http://strftimer.com/
For this project, the client specified that a user can update their own posts for a maximum of 10 minutes after they're created.
To implement this, we render the Edit button on a post only if it has been 10 minutes or less since the post was created.
<%= button_to "Edit", edit_post_path(post.id), :method => :get if (Time.now - post.created_at) / 60 <= 10 %>
Time.now - post.created_at
gives the time difference in seconds.