This file contains 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
#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> | |