Coder Social home page Coder Social logo

afn / browser-timezone-rails Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kbaum/browser-timezone-rails

0.0 2.0 0.0 58 KB

Rails engine that sets the Rails timezone to the browser time zone for each request.

Home Page: http://cowjumpedoverthecommodore64.blogspot.com/2013/03/setting-rails-timezone-to-users.html

License: MIT License

Ruby 82.34% JavaScript 3.49% CSS 2.69% HTML 11.48%

browser-timezone-rails's Introduction

BrowserTimezoneRails

Build Status Code Quality

Rails Engine which sets the Rails timezone to the browser's configured timezone for each request.

Installation

Add it to your Gemfile.

gem 'browser-timezone-rails'

Make sure you have each of the following entries in your application.js:

//= require js.cookie
//= require jstz
//= require browser_timezone_rails/set_time_zone

That's it! No other configuration is needed as it's all done for you with this gem including setting up your application controller to start using your users' zones.

How it works

The browsers timezone is set in a cookie using the awesome jsTimezoneDetect javascript library. That cookie is then read during each request to set the Rails timezone for that user.

You can also read more about this implementation here: Blog

For those of you who need or want to do this on the backend with just Rails, Ryan Bates has a good RailsCast on how to that: RailsCast #106

About that cookie

The cookie is set each full page request and lives for 365 days

Thread safety

Yes. It uses the Rails Time.zone method which is thread safe.

Caveat

The first request ever made by a user's browser to your app will not set the browser's time zone as the javascript that sets the cookie has not yet run on their browser. This will only happen once and for me it was not a problem.

Development

To run the tests, invoke bundle exec rspec.

browser-timezone-rails's People

Contributors

danielrsmith avatar fabn avatar kbaum avatar lalitkapoor avatar panozzaj avatar techfounder avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.