Automatically-updating Timeago Text With Rails-livestamp Gem

Automatically-updating Timeago Text with rails-livestamp Gem

rails-livestamp is a simple jQuery plugin that makes it easy to provides automatically updating text to your timestamped HTML elements.

Installation
Add this line to your application’s Gemfile:

Gemfile
1
gem 'rails-livestamp', '~> 1.1.3'

And then execute:

1
bundle install

Or install it yourself as:

1
gem install rails-livestamp

To use rails-livestamp add this require statement to your application.js file:

application.js
1
//= require rails-livestamp

Usage
No extra JavaScript required! Just use a with the data-livestamp attribute set to the desired Unix timestamp (in seconds), like this:

If you use ERB:

1
You discovered rails-livestamp <span data-livestamp="#{Time.now.to_i}"></span>.

If you use HAML:

1
2
You discovered rails-livestamp
%span{"data-livestamp" => "#{Time.now.to_i}"}.

And you will see something like this:

1
You discovered rails-livestamp a minutes ago.

Wait half a minute - the livestamp will update automatically.