Rails 4.1 heroku中的UnknownAttributeError(未知属性:uuid)

Rails 4.1 UnknownAttributeError (unknown attribute: uuid) in heroku

构建一个使用条带支付的应用程序,这适用于开发。我可以输入测试信用卡详细信息,并通过电子邮件确认。

但是当我 运行 使用 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 文件

class 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

在您的模型中包含 require 'securerandom' 并再次部署。