Question about Agile Rails


#1

anyone can explain me why in the Agile Depot Tutorial application they
use i.product_id
to find if a product already exist in the cart, because the cart
contains items which each of them reference a product.

I tried i.product_id like in the tutorial
and
i.product.i

all of these 2 notation works , but i find the second s more clean.

Any explanation will be fine

Regards

def add_product(product)
item = @items.find {|i| i.product_id == product.id} //and why not
i.product.id
if item
item.quantity +=1
else
@items << LineItem.for_product(product)
end
@total_price += product.price
end
end

The Crocodile