Rails nil can't be coerced into Float
- by alex
After adding items, attempting to view my cart leads me to this error:
nil can't be coerced into Float
with the math line in this method in my line_item model highlighted:
def total_price
product.price * quantity
end
line items create action
def create
product = Product.find(params[:product_id])
@line_item = @cart.add_product(product.id)
@line_item.quantity = params[:quantity]
view
<div id= "text_field"><%= text_field_tag 'quantity' %> </div>
<%= button_to 'Add to Cart', line_items_path(:product_id => product) %>
This has held me back for a couple days. (I'm new). Thanks.