Ruby
Feels like an easy refactor...
def new
if current_user.has_credit_card_on_file?
redirect_to edit_user_billing_path, :notice => "We've detected that you already have a credit card on file, please edit the details below"
end
end
def edit
unless current_user.has_credit_card_on_file?
redirect_to new_user_billing_path, :notice => "We've detected that you do not have a credit card on file, please add one below"
end
end
def new
if current_user.has_credit_card_on_file?
redirect_to edit_user_billing_path, :notice => "We've detected that you already have a credit card on file, please edit the details below"
end
end
def edit
unless current_user.has_credit_card_on_file?
redirect_to new_user_billing_path, :notice => "We've detected that you do not have a credit card on file, please add one below"
end
end
Refactorings
No refactoring yet !
August 20, 2011,
August 20, 2011 09:16,
permalink
No rating.
Login to rate!
def some_action
if current_user.has_credit_card_on_file?
render :new
else
render :edit
end
end
August 20, 2011,
August 20, 2011 09:17,
permalink
No rating.
Login to rate!
def some_action
if current_user.has_credit_card_on_file?
render :edit
else
render :new
end
end
I've got the method below which would seem like an easy refactoring job as they are both fairly similar kinds of logic, however, I'm having trouble figuring out a better way of doing it. I essentially just need to make sure a user can only get to either the edit action or new action based on whether or not they have a credit card on file, but never be able to access both. Any ideas?