Skip to content

Instantly share code, notes, and snippets.

@elecnix
Created August 24, 2009 00:36
Show Gist options
  • Select an option

  • Save elecnix/173564 to your computer and use it in GitHub Desktop.

Select an option

Save elecnix/173564 to your computer and use it in GitHub Desktop.
time zone per user
class ApplicationController < ActionController::Base
before_filter :restore_time_zone
after_filter :remember_time_zone
protected
def restore_time_zone
Time.zone = cookies[:time_zone] if cookies[:time_zone]
Time.zone = current_user.time_zone if current_user && current_user.time_zone
end
def remember_time_zone
cookies[:time_zone] = { :value => Time.zone.name, :expires => 1.year.from_now }
if current_user
current_user.time_zone = Time.zone.name
current_user.save
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment