Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Time ago in created_at?

I'm trying to use

<%= comment.created_at.time_ago_in_words(from_time) %>

but it wont work. I want the comment to show date as: 3 minutes ago, or 2 days ago.

What is the correct way to use this helper?

In my layout helper:

def time_ago_in_words(from_time, include_seconds_or_options = {})
    distance_of_time_in_words(from_time, Time.now, include_seconds_or_options)
end

Thanks!

like image 618
Gibson Avatar asked Jun 30 '14 12:06

Gibson


1 Answers

http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-time_ago_in_words

so it should be

<%= time_ago_in_words(comment.created_at) %>
like image 195
tirdadc Avatar answered Oct 15 '22 06:10

tirdadc