Skip to content

Instantly share code, notes, and snippets.

@thatrubylove
Created April 17, 2014 22:05
Show Gist options
  • Save thatrubylove/11014192 to your computer and use it in GitHub Desktop.
Save thatrubylove/11014192 to your computer and use it in GitHub Desktop.
an-exercise-in-refactoring-large-methods-in-ruby-example-2
def update
render if params[:credit_card]
process_order(params)
else
create_shipping_contact(params)
end
end
def process_order(params)
response = @order.process(params)
if response[:status] == "success"
{ :template => "orders/show" }
else
{ :json => response }
end
end
def create_shipping_contact(params)
if params[:shipping_contact].size > 0 &&
params[:shipping_address].size > 0
@order.create_shipping_contact(params[:shipping_contact],
params[:shipping_address])
end
{ :template => "orders/show" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment