From 779c29ee092d3392196df0c7ba1c4b09d6811afd Mon Sep 17 00:00:00 2001 From: XuZhiqing <1687088161@qq.com> Date: Wed, 14 Aug 2019 17:45:34 +0800 Subject: [PATCH] #14 add migration file. improve method set_time_zone. # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want to. # An empty message aborts the commit. # # Date: Wed Aug 14 17:45:34 2019 +0800 # # On branch user-time-zone # Your branch is up to date with 'origin/user-time-zone'. # # Changes to be committed: # modified: app/controllers/application_controller.rb # new file: db/migrate/20190809022738_add_user_time_zone.rb # new file: db/migrate/20190814094307_add_user_time_zone.rb # # Changes not staged for commit: # deleted: db/migrate/20190814094307_add_user_time_zone.rb # # Untracked files: # .generators # .idea/ # .rakeTasks # --- app/controllers/application_controller.rb | 2 +- db/migrate/20190809022738_add_user_time_zone.rb | 5 +++++ db/migrate/20190814094307_add_user_time_zone.rb | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20190809022738_add_user_time_zone.rb create mode 100644 db/migrate/20190814094307_add_user_time_zone.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d1fca1dd9..98471625b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -60,6 +60,6 @@ def #{s}!(redirect_url: nil) private def set_time_zone - Time.zone = current_user.time_zone if current_user and current_user.time_zone.present? + Time.zone = current_user.time_zone if current_user&.time_zone&.present? end end diff --git a/db/migrate/20190809022738_add_user_time_zone.rb b/db/migrate/20190809022738_add_user_time_zone.rb new file mode 100644 index 000000000..ca85d0f7c --- /dev/null +++ b/db/migrate/20190809022738_add_user_time_zone.rb @@ -0,0 +1,5 @@ +class AddUserTimeZone < ActiveRecord::Migration[6.0] + def change + add_column :users, :time_zone, :string + end +end diff --git a/db/migrate/20190814094307_add_user_time_zone.rb b/db/migrate/20190814094307_add_user_time_zone.rb new file mode 100644 index 000000000..ca85d0f7c --- /dev/null +++ b/db/migrate/20190814094307_add_user_time_zone.rb @@ -0,0 +1,5 @@ +class AddUserTimeZone < ActiveRecord::Migration[6.0] + def change + add_column :users, :time_zone, :string + end +end