Created
December 20, 2009 01:38
-
-
Save ianlevesque/260321 to your computer and use it in GitHub Desktop.
Automatically set the TimeZone in Rails >= 2.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// detect time zone | |
Event.observe(window, 'load', function() { | |
var date = new Date(); | |
date.setTime(date.getTime() + (1000*24*60*60*1000)); | |
var expires = "; expires=" + date.toGMTString(); | |
var offset = -(new Date().getTimezoneOffset() / 60); | |
document.cookie = "timezone=" + offset + expires + "; path=/"; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
before_filter :set_timezone | |
protected | |
def set_timezone | |
tz_off = cookies[:timezone] | |
Time.zone = ActiveSupport::TimeZone[tz_off.to_i] unless tz_off.nil? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment