0.0
No commit activity in last 3 years
No release in over 3 years
Localize server times in your view.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.3
>= 0
 Project Readme

Localtime::Rails

This gem just packages up some javascript that will help turn server timestamps (i.e. created_at) to local browser time.

Installation

Add this line to your application's Gemfile:

gem 'localtime-rails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install localtime-rails

For rails, add this line to application.js:

//= require localtime

Usage

Let's say you're listing users...

%table
  - @users.each do |user|
    %tr
      %td= user.name
      %td= user.created_at

...user.created_at will yield something like this:

2013-11-12 21:10:02 UTC

Now, you can take that "created_at" server time stamp, and make it relevant to the user...

%table
  - @users.each do |user|
    %tr
      %td= user.name
      %td.local-time
        = user.created_at

...now user.created_at will look something like this:

11/12/2013 7:10 AM

If you have some sort of asynchronous Javascript that's executing after the initial page load, you can always call the function...

localizeTime();

Sample App

You can see a sample rails app here: localtime-example

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request