Neil
Neil

Reputation: 569

Rails 4.1 UnknownAttributeError (unknown attribute: uuid) in heroku

Building an app which uses stripe payments , this works on development. I can enter the test credit card details , and it goes through with email confirmation.

But when i run this on production using Heroku, I get the error We're sorry, but something went wrong. heroku logs shows the following

 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"=>"[email protected]", "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

get this error ?? ActiveRecord::UnknownAttributeError (unknown attribute: uuid): which I have used in my charges controller.rb file

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

have done heroku restart and added the uuid to my purchases model

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

Upvotes: 1

Views: 583

Answers (1)

sansarp
sansarp

Reputation: 1466

Include require 'securerandom' in your model and deploy again.

Upvotes: 1

Related Questions