Skip to content

Commit

Permalink
Moving time_zone from users to profiles table. Fixing migration down …
Browse files Browse the repository at this point in the history
…of last_activity_at
  • Loading branch information
Tair Assimov authored and stevenbristol committed Oct 7, 2008
1 parent 6311417 commit 26961b8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/profiles/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/006_add_profile_last_activity_at.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ def self.up
end

def self.down
remove_column :last_activity_at
remove_column :profiles, :last_activity_at
end
end
12 changes: 12 additions & 0 deletions db/migrate/007_move_timezone_to_profiles.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 26961b8

Please sign in to comment.