views:

215

answers:

3

I need to show natural dates like

  1. "few seconds ago"
  2. "21 minutes ago"

Is there something built in to the rails? Or may be third party? This is not hard to implement, but I do not want to invent the wheel.

+7  A: 

I think what you are looking for is time_ago_in_words

Matt Briggs
Yes, thanks I will try.
Mike Chaliy
It works great for this purpose -- I, unfortunately, only found it recently. I actually spent four hours one day replicating this behavior and another two releasing it as a plugin. What a waste.
James A. Rosen
+1  A: 

Also check out the chronic gem

http://chronic.rubyforge.org/

Henry
Chronic is parser, I need exactly opposite.
Mike Chaliy
I reread your question, I mis-understood. Sorry
Henry
+2  A: 

An interesting approach to consider is doing time-to-word conversion on the client side with javascript. This can keep your pages cacheable while still presenting relative times to the end user.

Darragh Curran has released a javascript implementation of just such functionality and written up a short explanation of how to use it in a Rails application.

Another interesting advantage of this technique is that you can dynamically update the description of the time without the user leaving the page.

Duncan Beevers
Good stuff, I fill look on this closely.
Mike Chaliy