small medium large xlarge

Generic-user-small
21 Feb 2012, 00:47
LED (3 posts)

by following all of the snippets in the book it lead me to the error

nil can’t be coerced into BigDecimal

i line cause me the error

def total_price line_items.to_a.sum { |item| item.total_price } end

def total_price product.price * quantity end

its just like multiplying a null with a number

thanks for the help more power to us

Generic-user-small
02 Mar 2012, 03:30
Michael Ryan Soileau (5 posts)

Same problem, a few others have hit it as well on other forums I’ve read.

I temporarily solved it by running rake db:reset and rebuilding, but it came back once again with a vengeance. My guess is I’ll have to start from the beginning.

Generic-user-small
02 Mar 2012, 03:41
Xavier John (21 posts)

LED, you might have missed the default: 1 when adding quantity to the line_items table. Just update all the rows and set quantity to 1.

Add the default to the migration file if it is missing.

class AddQuantityToLineItems < ActiveRecord::Migration

def change

add_column :line_items, :quantity, :integer,  default: 1

end

end

You must be logged in to comment