From 26961b808da6c3276ef179fe0cce978ce62157e3 Mon Sep 17 00:00:00 2001 From: Tair Assimov Date: Tue, 7 Oct 2008 09:38:19 +0300 Subject: [PATCH] Moving time_zone from users to profiles table. Fixing migration down of last_activity_at --- app/controllers/application.rb | 2 +- app/controllers/profiles_controller.rb | 2 +- app/views/profiles/_form.html.erb | 2 +- db/migrate/006_add_profile_last_activity_at.rb | 2 +- db/migrate/007_move_timezone_to_profiles.rb | 12 ++++++++++++ 5 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 db/migrate/007_move_timezone_to_profiles.rb diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 61cf8eb..42e7a16 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -23,7 +23,7 @@ def pagination_defaults def set_profile @p = @u.profile if @u && @u.profile - Time.zone = @u.time_zone if @u && @u.time_zone + Time.zone = @p.time_zone if @p && @p.time_zone @p.update_attribute :last_activity_at, Time.now if @p end diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index 09bda52..f2506e4 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -51,7 +51,7 @@ def edit def update case params[:switch] when 'name','image' - if @profile.update_attributes(params[:profile]) && @user.update_attributes(params[:user]) + if @profile.update_attributes params[:profile] flash[:notice] = "Settings have been saved." redirect_to edit_profile_url(@profile) else diff --git a/app/views/profiles/_form.html.erb b/app/views/profiles/_form.html.erb index 1360901..319c2b1 100644 --- a/app/views/profiles/_form.html.erb +++ b/app/views/profiles/_form.html.erb @@ -20,7 +20,7 @@ <%= p.text_field :last_name %> <%= p.text_field :location %> <%= p.front :timezone %> - <%= time_zone_select :user, :time_zone, TimeZone.us_zones %> + <%= time_zone_select :profile, :time_zone, TimeZone.us_zones %> <%= p.back %> <%= p.text_field :website %> <%= p.text_field :flickr %> diff --git a/db/migrate/006_add_profile_last_activity_at.rb b/db/migrate/006_add_profile_last_activity_at.rb index 2118917..d6bd12a 100644 --- a/db/migrate/006_add_profile_last_activity_at.rb +++ b/db/migrate/006_add_profile_last_activity_at.rb @@ -4,6 +4,6 @@ def self.up end def self.down - remove_column :last_activity_at + remove_column :profiles, :last_activity_at end end diff --git a/db/migrate/007_move_timezone_to_profiles.rb b/db/migrate/007_move_timezone_to_profiles.rb new file mode 100644 index 0000000..4975cf4 --- /dev/null +++ b/db/migrate/007_move_timezone_to_profiles.rb @@ -0,0 +1,12 @@ +class MoveTimezoneToProfiles < ActiveRecord::Migration + def self.up + add_column :profiles, :time_zone, :string, :default => "UTC" + remove_column :users, :time_zone + execute "update profiles set time_zone='UTC'" + end + + def self.down + remove_column :profiles, :time_zone + add_column :users, :time_zone, :string, :default => "UTC" + end +end