On 21.02.2012, at 14:08, ruby LED wrote:

> class LineItem < ActiveRecord::Base
>  belongs_to :product
>  belongs_to :cart
> 
>  def total_price
>     if product.price
>       product.price = product.price * quantity
>     else
>        0.to_d
>     end
>   end
> end
> 

So.

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.

2) Actually I didn't see how quantity is set up? Looking at your previous code 
it must be method 'quantity'.

PS. Why are you writing product.price=?

-- 
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