The rails-livestamp is a simple jQuery plugin that provides auto-updating timeago text to your timestamped HTML elements, which will update automatically as time goes by. ISO 8601 timestamps are also supported.
Add this line to your application's Gemfile:
gem 'rails-livestamp', '~> 1.1.3'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rails-livestamp
To use rails-livestamp add this require statement to your application.js file:
//= require rails-livestamp
No extra JavaScript required! Just use a <span>
with the data-livestamp attribute set to the desired Unix timestamp (in seconds), like this:
If you use ERB:
You discovered rails-livestamp <span data-livestamp="#{Time.now.to_i}"></span>.
If you use HAML:
You discovered rails-livestamp
%span{"data-livestamp" => "#{Time.now.to_i}"}.
And you will see something like this:
You discovered rails-livestamp a minutes ago.
Wait half a minute - the livestamp will update automatically.
See the livestamp documentation.
Copyright (c) 2015 - Present, Matt Bradley ( Livestamp.js Maintainer ), Bunlong VAN ( Maintainer )