我正在开发一款应用程序,允许会员升级到高级会员(使用Stripe付款后)以访问其他功能。我在测试模式下仅在生产环境中使用Stripe,因此我正在寻找一种方法在Heroku控制台中创建高级用户。难道是这样?:如何在测试模式下使用Stripe时创建一个高级用户来测试我的应用程序的高级功能?
user = User.find_by(name:’existing user name’)
user.update_attribute(‘premium’).save
我有t.boolean "premium"
在我schema.rb文件。
我是编程新手,所以请让我知道你是否需要任何额外的文件信息。谢谢!
编辑更新:这是我的收费控制器代码:
class ChargesController < ApplicationController
def new
@stripe_btn_data = {
key: "#{ Rails.configuration.stripe[:publishable_key] }",
description: 'Premium Membership',
amount: 1_299
}
end
def create
@amount = params[:amount]
customer = Stripe::Customer.create(
email: current_user.email,
card: params[:stripeToken]
)
charge = Stripe::Charge.create(
customer: customer.id,
amount: @amount,
description: 'Premium Membership',
currency: 'usd'
)
current_user.update_attribute(:premium, true)
redirect_to wikis_path, flash: { notice: "Congratulations, #{current_user.email}, on becoming a premium member!"}
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to new_charge_path
end
end
我理解这个概念,但我没有@ user.update_with_payment在我的收费控制器或我的代码中的任何其他地方。现在我已经发布了我的收费控制器了吗?谢谢! – 2014-09-25 14:38:02
如果你想在不更改代码的情况下显式更新数据库中的用户,那么你可以只做'fourfourjew'在顶部建议的内容 - 抓住用户('user = User.find(1)'),然后使用AR 'update_attribute'方法,该方法接受属性,然后将值设置为参数:'user.update_attribute(:premium,true)' – Sasha 2014-09-25 18:24:10
Sasha,是否有一个原因,即fourfourjew提到不更新控制台中的用户对象?它可能会混淆我的生产数据库吗? – 2014-09-25 20:18:46