Hi guys,
Is there a standard function/gem in rails that lets me format times in a facebookish way, like “x minutes ago”? Ideally one that works well together with a similar jquery library for live updates?
Thanks
Martin
Hi guys,
Is there a standard function/gem in rails that lets me format times in a facebookish way, like “x minutes ago”? Ideally one that works well together with a similar jquery library for live updates?
Thanks
Martin
I don’t know of a good gem solution (though it would be great if there were one because this is a problem that has been solved and re-solved too many times) but DHH did a blog post a few years back that explains exactly how to implement this in a relatively simple way.
http://37signals.com/svn/posts/1557-javascript-makes-relative-times-compatible-with-caching
Rails has inbuilt helpers for such kind of stuff.
Check out the following docs, method like distance_of_time_in_words Rails 2.3 - Module: ActionView::Helpers::DateHelper
Rails 3.0 - ActionView::Helpers::DateHelper
Awesome, thank you.
Rails rocks!