Skip to content

Instantly share code, notes, and snippets.

@msroot
Created July 4, 2015 13:22
Show Gist options
  • Select an option

  • Save msroot/a539d0b0cbf9cbee2adb to your computer and use it in GitHub Desktop.

Select an option

Save msroot/a539d0b0cbf9cbee2adb to your computer and use it in GitHub Desktop.
set_time_zone
#1 .ApplicationController
class ApplicationController < ActionController::Base
around_filter :set_time_zone
def set_time_zone(&block)
time_zone = current_user.shop.try(:timezone) || 'UTC'
Time.use_zone(time_zone, &block)
end
end
#2. Generate migration
class AddTimezoneToShops < ActiveRecord::Migration
def change
add_column :shops, :timezone, :string, :default => 'Europe/Athens'
end
end
#3. Set a form
<div class="form-group">
<%= f.label :timezone, :class => "col-lg-2 control-label" %>
<div class="col-lg-10">
<%= f.input :timezone, :collection => Timezone::Zone.names, :label => false ,:include_blank => false,
:class => "form-control" %>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment