Facebook’s news feed popularized the relative timestamp format of “X hours ago”. For good reason too…why print an absolute timestamp so that people have to do the relative calculation in their head? It’s one less step for the user, and to be fair, pretty easy to implement.
Rails helpers to the rescue
Rails has a view helper aptly named
time_ago_in_words. If you use the
created_at attribute from a record, you could easily reference a relative timestamp from a corresponding view:
Posted: <%= time_ago_in_words(post.created_at) %> ago
That’s great! But not enough…what happens when a user stays on the page for 10 min. and the latest post was no longer posted “1 minute ago”? Asking them to refresh the page every 10 minutes is no longer an acceptable answer.
continue reading →