Calculate the elapsed time after creating a record

0

I would like to know how to calculate the time between creating a record (created_at) and the current time . My intention is to show this difference in seconds, minutes, hours, or days that this occurred. Is there a gem / method to accomplish this task?

    
asked by anonymous 13.12.2017 / 21:07

1 answer

1

I solved the question using the following method time_ago_in_words

In your view use the code:

há <%= time_ago_in_words(notification.created_at) %>

If your date passed as a parameter in the method is 19:00 13/12/2017 and the current time is 19:07 13/12/2017 , the result will be: há 07 minutos . It also works when the difference is for seconds, hours, and days.

    
13.12.2017 / 21:07