Nil can't be coerced into BigDecimal

PS. Why are you writing product.price=?
i belive it is same with product.price * quantity
to show the sum of all products inside my cart

Logic, logic, logic.

product - is a stand alone instance or One product. Why Would it ever
have the multiplied price with ‘quantity’ ?.

I remember many years ago I read the beginner’s book “Agile Web
Development with Rails”, is that example from it? I think you missed
something.
thank very much for the effort yes this is from the book agile web
development with rails sorry about it im just starting to learn ruby on
rails, uhm i didnt miss anything its just other snippets in the book is
not properly working :frowning:

On 21.02.2012, at 15:29, ruby LED wrote:

Valery K. wrote in post #1047990:

I agree that:

  1. current_item = LineItem.new(:product_id=>product_id) = BAD IDEA.
    Because, if you pass the invalid product ID, LineItem would be
    initialized as well, but the .product association would return nil.
    do you think current_item = line_items.build(:product_id => product_id)
    is better?

no, the correct way is:

product = Product.find(product_id) # it will raise
AcriveRecord::RecordNotFound if invalid product_id passed.
current_item = LineItem.new(:product => product) # or current_item =
LineItem.new; current_item.product = product

  1. Actually I didn’t see how quantity is set up? Looking at your
    previous code it must be method ‘quantity’.
    i dont have a method quantity

In this case it does not work ever. def total_count - is an instance
method.
If you use ‘quantity’, so it just MUST be an another instance method or
local variable. There is something wrong with app’s logic.

PS. Why are you writing product.price=?
i belive it is same with product.price * quantity
to show the sum of all products inside my cart

Logic, logic, logic.

product - is a stand alone instance or One product. Why Would it ever
have the multiplied price with ‘quantity’ ?.

I remember many years ago I read the beginner’s book “Agile Web
Development with Rails”, is that example from it? I think you missed
something.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs