Mar
04
Timezone support in Rails 2.1+
Posted by Michael Cindric in ruby on rails | No Comments »
Setting up Timezone support in the past was a pain, but now with rails 2.1 and above it’s easy and done in minutes. Here is what you need to do
# config/environment.rb config.time_zone = "Pacific Time (US & Canada)" # controllers/application.rb before_filter :set_user_time_zone private def set_user_time_zone Time.zone = current_user.time_zone if logged_in? end # Add to field to user model add_column :users, :time_zone, :string
Once you have this in place then to user the users timezone in your app its just something like this
# To use users timezone rather then server time current_user.time_zone.today




