Skip to content

Instantly share code, notes, and snippets.

@gravis
Created April 15, 2009 12:34
Show Gist options
  • Save gravis/95741 to your computer and use it in GitHub Desktop.
Save gravis/95741 to your computer and use it in GitHub Desktop.
# Render a timestamp suitable for javascript substitution (jquery.timeago)
# Sorry for copyright, I can't remember where I found this piece of code ! Do not hesitate to claim it
def timeago(time, options = {})
options[:class] ||= "timeago"
content_tag(:abbr, time.to_s, options.merge(:title => time.getutc.iso8601)) if time
end
# don't forget to add this to substitute times (HAML) :
# :javascript
# $(document).ready(function() {
# $('abbr[class*=timeago]').timeago();
# });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment