Skip to content

Instantly share code, notes, and snippets.

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