Created
April 17, 2014 20:21
-
-
Save thatrubylove/11009313 to your computer and use it in GitHub Desktop.
an-exercise-in-refactoring-large-methods-in-ruby-2
This file contains 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
... | |
def update | |
if (params[:user][:password].blank? && params[:user][:password_confirmation].blank?) | |
params[:user].delete(:password) | |
params[:user].delete(:password_confirmation) | |
end | |
if params[:user][:photo_attributes] | |
Photos::Manipulation.update_resource_photo(current_user.photo || Photo, params[:user][:photo_attributes], current_user) | |
current_user.photo.try(:reload) | |
end | |
if current_user.photo.nil? || current_user.photo.cropped? | |
update! do |success, failure| | |
@daily_snapshot = @user.daily_snapshots.new_to_old.first | |
failure.html { render :basics } | |
success.html { | |
flash.notice = 'successfully updated' | |
if @user.basics? || params[:next_screen] == 'accounts_user' | |
sign_in(@user, :bypass => true) if (@user.valid_password?(params[:user][:password]) && params[:user][:password] == params[:user][:password_confirmation] && !@user.partner_editor?) | |
redirect_to basics_user_path(@user) and return if @user.complete? && !@user.partner_editor? | |
if @user.partner_editor? | |
redirect_to user_path(@user.invited_by_id) | |
else | |
redirect_to accounts_user_path(@user) | |
end | |
elsif @user.interests? && params[:next_screen] == 'show_user' | |
@user.complete unless request.xhr? | |
redirect_to user_path(@user) | |
else | |
redirect_to interests_user_path(@user) and return if @user.complete? && params[:next_screen] == 'show_user' | |
redirect_to basics_user_path(@user) and return if @user.complete? && params[:next_screen] == 'accounts_user' | |
redirect_to user_path(@user) | |
end | |
} | |
end | |
else | |
render :basics | |
end | |
end | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment