public
Last active — forked from bkeepers/application.js

  • Download Gist
application.js
JavaScript
1 2 3
jQuery(function() {
$.cookie('tz', (new Date()).getTimezoneOffset());
});
application_controller.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
class ApplicationController < ActionController::Base
before_filter :set_timezone
# …
private
 
def set_timezone
if current_user && browser_timezone && browser_timezone.name != current_user.time_zone
current_user.update_attributes :time_zone => browser_timezone.name
end
Time.zone = current_user ? current_user.time_zone : browser_timezone
end
def browser_timezone
@browser_timezone ||= begin
ActiveSupport::TimeZone[-cookies[:tz].to_i.minutes]
end if cookies[:tz].present?
end
 
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.