please take a look here: http://twitter.com/#!/techcrunch
Notice that time is displayed with the following logic:
- If
created_at
, is under 24hrs, it display XXX hours ago, or 1 hour ago - If
created_at
, is over 24hrs, it display the X Feb
Does Rails have this capability built in or is a helper needed? If so, what's the smart way to solve for this type of ou开发者_如何学编程tput?
Thanks
You are probably looking for the time_ago_in_words helper method.
i know this is a bit late but this is what i use in my view to display my messages:
<% if message.created_at > Time.now.beginning_of_day %>
<%="#{time_ago_in_words(message.created_at)} ago"%> # 3 minutes ago, less than a minute ago
<% else %>
<%= message.created_at.strftime("%b %d, %Y") %> # Jun 29, 2012
<% end %>
Can be extracted into a helper method. hope it helps
精彩评论