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,用户也会保存?返回假。没有其他任何事情发生,因为没有发送电子邮件,没有设置 session[:user_id] 也没有重定向到 root_path。Else 块执行并呈现 :new 并显示一个闪存通知,说明卡已被拒绝。
如果charge.successful,我试图避免创建用户?返回假。关于如何去做的任何想法?