0
def create
@user = User.create(user_params)
if @user.valid?
charge = StripeWrapper::Charge.create(amount: 999, card: params[:stripeToken], description: "Sign up charge for #{@user.email}")
if charge.successful?
@user.save
User.inviter_and_invited_follow_each_other(@user)
AppMailer.delay.welcome(current_user)
session[:user_id] = @user.id
flash[:notice] = "You have successfully registered and will be logged in."
redirect_to root_path
else
flash[:notice] = charge.error_message
render :new
end
else
render :new
end
end
即使在charge.successful時,用戶仍可保存?返回false。沒有其他事情發生,因爲沒有發送電子郵件,session [:user_id]沒有被設置,也沒有被重定向到root_path。否則,塊執行並渲染:new並顯示閃現通知,說明卡被拒絕。如何避免創建後保存? Rails
我想避免用戶創建,如果charge.successful?返回false。有關如何解決這個問題的任何想法?
謝謝,我不敢相信我沒有弄明白這一點。休息時間! – user2170878