Rails nil can't be coerced into Float

Posted by alex on Stack Overflow See other posts from Stack Overflow or by alex
Published on 2014-08-19T04:14:26Z Indexed on 2014/08/19 4:20 UTC
Read the original article Hit count: 145

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby