Created
July 4, 2015 13:22
-
-
Save msroot/a539d0b0cbf9cbee2adb to your computer and use it in GitHub Desktop.
set_time_zone
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
| #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