我該如何幹下面的代碼?我需要設置一系列的ELSE嗎?我通常會發現「如果遇到這種情況,停止」,「如果遇到這種情況,停止」,而不是一堆嵌套的ifs。Ruby操作:如何避免一堆退貨來暫停執行?
我發現redirect_to的和渲染不停止動作執行...
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
返回false會導致Rails渲染nothign? – Alexandre 2010-03-13 23:05:52