> 
> def add_product(product_id)
>    current_item = line_items.where(:product_id => product_id).first
> 
>     if current_item
>        current_item.quantity = current_item.quantity.to_i + 1
>      else
>        current_item = LineItem.new(:product_id=>product_id)
>        line_items << current_item

        Ok, let's imagine. You add new LineItem and product.price is nil or 
quantity is nil
        then 
        product.price * quantity
        would raise error "nil can't be coerced into…"

        Check if product price or quantity is nil after initialize LineItem.new

>      end
>        current_item
>   end
> 

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to