3
在模型中使用方法時,是否可以呈現條紋錯誤消息作爲註釋。這是我目前處理模型中的條紋錯誤
def create
@donation = @campaign.donations.create(donation_params)
if @donation.save_with_payment
redirect_to @campaign, notice: 'Card charged successfully.'
else
render :new
end
end
控制器和我的方法是,像這樣
def save_with_payment
customer = Stripe::Customer.create(
:email => email,
:card => stripe_token
)
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => donation_amount,
:description => 'Rails Stripe customer',
:currency => 'usd'
)
end
我從其他人注意到exmaples這條具有
rescue Stripe::error
rescue Stripe::InvalidRequestError => e
但是我不知道如何抓住這些錯誤,然後把它們放在通知內
任何幫助讚賞謝謝
你想如何處理它?你想'save_with_payment'來表示驗證失敗嗎?另外,你有一個實例方法而不是一個類方法。 –
對不起,我的方法混在一起,謝謝澄清。我想處理save_with_payment中的錯誤,並通過可能的通知通過通知向用戶顯示錯誤 – Richlewis