剥离充电后数据未保存 (rails)
data not saving after strip charge (rails)
您好,我的测试应用程序有问题。这个应用程序有一个模型叫做用户可以接受积分。这些积分是在卡上充值后购买的。我遇到的问题是,一旦收费完成,积分就会出现,但一旦您更改页面,积分就会消失。它没有保存在数据库中。任何帮助都很棒。这是 charges.rb
class ChargesController < ApplicationController
def new
end
def create
# Amount in cents
@amount = 500
customer = Stripe::Customer.create(
:email => params[:stripeEmail],
:source => params[:stripeToken]
)
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => @amount,
:description => 'Rails Stripe customer',
:currency => 'USD'
)
current_user.points = current_user.points + 500
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to new_charge_path
end
end
您需要添加:
current_user.save
在这一行之后:
current_user.points = current_user.points + 500
您好,我的测试应用程序有问题。这个应用程序有一个模型叫做用户可以接受积分。这些积分是在卡上充值后购买的。我遇到的问题是,一旦收费完成,积分就会出现,但一旦您更改页面,积分就会消失。它没有保存在数据库中。任何帮助都很棒。这是 charges.rb
class ChargesController < ApplicationController
def new
end
def create
# Amount in cents
@amount = 500
customer = Stripe::Customer.create(
:email => params[:stripeEmail],
:source => params[:stripeToken]
)
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => @amount,
:description => 'Rails Stripe customer',
:currency => 'USD'
)
current_user.points = current_user.points + 500
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to new_charge_path
end
end
您需要添加:
current_user.save
在这一行之后:
current_user.points = current_user.points + 500