Comment sécher le code ci-dessous? Dois-je configurer un tas d'ELSE? Je trouve habituellement le "si cela est rencontré, arrêtez", "si cela est rencontré, arrêtez", plutôt qu'un tas d'ifs imbriqués.Ruby Actions: Comment éviter un tas de retours pour arrêter l'exécution?
J'ai découvert que redirect_to et ne rendent pas arrêter l'exécution de l'action ...
def payment_confirmed
confirm_payment do |confirmation|
@purchase = Purchase.find(confirmation.order_id)
unless @purchase.products_match_order_products?(confirmation.products)
# TODO notify the buyer of problems
return
end
if confirmation.status == :completed
@purchase.paid!
# TODO notify the user of completed purchase
redirect_to purchase_path(@purchase)
else
# TODO notify the user somehow that thigns are pending
end
return
end
unless session[:last_purchase_id]
flash[:notice] = 'Unable to identify purchase from session data.'
redirect_to user_path(current_user)
return
end
@purchase = Purchase.find(session[:last_purchase_id])
if @purchase.paid?
redirect_to purchase_path(@purchase)
return
end
# going to show message about pending payment
end
renvoyer false provoque Rails à rendre nothign? – Alexandre