Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tz_magic

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tz_magic

  • 0.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

= TzMagic

= Description

While every sysadmin worth his or her salt runs their server in the UTC timezone, it is occasionally useful, even necessary, to know the timezone that the end user's browser is set to. Surprisingly, there isn't an easy way to do this - you'd think that the browser might supply that in a header, but no... getting it is an exercise in plumbing together raw pieces of the internet. This gem gives that to your average rails app with a minimum of fuss.

= How to use it

Its a rails engine. You install it via a gem, then include various bits.

== add this to your Gemfile with:

gem 'tz-magic'

== then wire it up in your rails app:

add this line to your config/routes.rb file:

mount TzMagic::Engine => "/tz_magic"

add this line to your helpers/application_helper.rb file:

include TzMagic::ApplicationHelper

add this line to your app/assets/javascripts/application.js file:

require tz_magic/application

add this line to the controller that you need to ensure the timezone exists for (application_controller.rb is an acceptable, if brute-force option):

include TzMagic::BeforeFilter

you now have a helper you can refer to in your controllers or views like:

time_zone

or

<%= time_zone.name %>

This is a full fleged TimeZone instance.

= How it works

by including the TzMagic::BeforeFilter into your controller, you are adding a check that the user's session contains a :timezone_name element. If that element exists, all is fine. If it doesn't exist:

  • we redirect the user to our /timezone/new view
  • this view runs some javascript that determines the user's timezone, then submits it via an ajax push to /timezone
  • this hits our timezone#create method, which sets the cookie and returns the original url the user was going to via a json block.
  • the javascript receives the json payload, extracts the original url, and redirects, with the timezone happily in the session.

= the magic javascript code

The javascript at the heart of this Rube Goldberg contraption is Copyright (c) 2012 Jon Nylander, project maintained at https://bitbucket.org/pellepim/jstimezonedetect

= contributing

The usual. Fork, modify, test, pullup request.

FAQs

Package last updated on 16 Oct 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc