Skip to content

Instantly share code, notes, and snippets.

@sprite2005
Created February 1, 2009 21:46
Show Gist options
  • Save sprite2005/56670 to your computer and use it in GitHub Desktop.
Save sprite2005/56670 to your computer and use it in GitHub Desktop.
def update
@user.attributes = params[:user]
@metro_areas, @states = setup_locations_for(@user)
unless params[:metro_area_id].blank?
@user.metro_area = MetroArea.find(params[:metro_area_id])
@user.state = (@user.metro_area && @user.metro_area.state) ? @user.metro_area.state : nil
@user.country = @user.metro_area.country if (@user.metro_area && @user.metro_area.country)
else
@user.metro_area = @user.state = @user.country = nil
end
begin
@album = @user.albums.find_by_name("Profile Pictures")
rescue ActiveRecord::RecordInvalid
@album = @user.albums.new(:name => "Profile Pictures")
@album.save!
end
@avatar = @album.photos.build(params[:avatar])
@avatar.user = @user
@user.avatar = @avatar if @avatar.save
@user.tag_list = params[:tag_list] || ''
if @user.save!
@user.track_activity(:updated_profile)
flash[:notice] = :your_changes_were_saved.l
unless params[:welcome]
redirect_to user_path(@user)
else
redirect_to :action => "welcome_#{params[:welcome]}", :id => @user
end
end
rescue ActiveRecord::RecordInvalid
render :action => 'edit'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment