构建使用条带付款的应用,这适用于开发。我可以输入测试信用卡详细信息,并通过电子邮件确认。
但是当我使用Heroku在生产中运行时,我收到错误我们很抱歉,但出了点问题。 heroku日志显示以下
Started POST "/charges" for 80.2.226.13 at 2015-03-27 16:05:31 +0000
2015-03-27T16:05:31.871211+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"2jvX1N56k0a3meU3jV2SdeVq9y7rRFjg03w8aSBRYC8=", "stripeToken"=>"tok_15kzxd4Czb5bpuHdZzkzroA5", "stripeEmail"=>"neil@spark48.com", "amount"=>"499"}
2015-03-27T16:05:31.871173+00:00 app[web.1]: Processing by ChargesController#create as HTML
2015-03-27T16:05:33.406666+00:00 app[web.1]: Completed 500 Internal Server Error in 1535ms
2015-03-27T16:05:33.407849+00:00 app[web.1]: app/controllers/charges_controller.rb:19:in `create'
2015-03-27T16:05:33.407851+00:00 app[web.1]:
2015-03-27T16:05:33.407847+00:00 app[web.1]: **ActiveRecord::UnknownAttributeError (unknown attribute: uuid):**
2015-03-27T16:05:33.407850+00:00 app[web.1]:
2015-03-27T16:05:33.407844+00:00 app[web.1]:
2015-03-27T16:05:33.416304+00:00 heroku[router]: at=info method=POST path="/charges" host=railsapp2015.herokuapp.com request_id=f514ee9e-a111-4547-b89d-29eab4931c0a fwd="80.2.226.13" dyno=web.1 connect=2ms service=1544ms status=500 bytes=1754
得到这个错误? ActiveRecord :: UnknownAttributeError(未知属性:uuid): 我在充电控制器中使用了controller.rb文件
类ChargesController< ApplicationController中
def create
# Amount in cents
customer = Stripe::Customer.create(
:email => params[:stripeEmail],
:card => params[:stripeToken]
)
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => params[:amount],
:description => 'Open Cinema',
:currency => 'gbp'
)
purchase = Purchase.create(email: params[:stripeEmail],
card: params[:stripeToken], amount: params[:amount],
description: charge.description, currency: charge.currency,
customer_id: customer.id, product_id: 1, uuid: SecureRandom.uuid)
redirect_to purchase
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to charges_path
end
end
已完成heroku重启并将uuid添加到我的购买模式
class AddUuidToPurchases < ActiveRecord::Migration
def change
add_column :purchases, :uuid, :string
end
end
class ChargesController < ApplicationController
def create
# Amount in cents
require 'SecureRandom'
customer = Stripe::Customer.create(
:email => params[:stripeEmail],
:card => params[:stripeToken]
)
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => params[:amount],
:description => 'Open Cinema',
:currency => 'gbp'
)
purchase = Purchase.create(email: params[:stripeEmail],
card: params[:stripeToken], amount: params[:amount],
description: charge.description, currency: charge.currency,
customer_id: customer.id, product_id: 1, uuid: SecureRandom.uuid)
redirect_to purchase
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to charges_path
end
end
答案 0 :(得分:1)
在模型中加入require 'securerandom'
并重新部署。