Created
August 24, 2009 00:36
-
-
Save elecnix/173564 to your computer and use it in GitHub Desktop.
time zone per user
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 :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