Skip to content

Instantly share code, notes, and snippets.

@zheileman
Created February 6, 2012 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zheileman/1751193 to your computer and use it in GitHub Desktop.
Save zheileman/1751193 to your computer and use it in GitHub Desktop.
jQuery timeago rails helper
# This will work together with this jQuery timeago plugin fork:
# https://github.com/zheileman/jquery-timeago
# Please note the original jQuery timeago plugin use the 'title' to store the timestamp.
# This forked version use a 'data-time' attribute to store the timestamp and have
# a configurable setting to enable/disable overwriting the title with tag's content.
#
# $.timeago.settings.overwriteTitle = [true|false]
def js_timeago(time, options = {})
css_classes = (options.delete(:class) || "").strip.split | ["timeago"]
content_tag(:span, time.to_s, options.merge('data-time' => time.getutc.iso8601, :class => css_classes.join(' '))) if time
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment