I’ve just completed D3 and there’s something that is bugging me. I am new with rails, so forget me if the question is obvious.
In the line items controller, while creating a new line item, we wrote this line:
@cart = current_cart
product = Product.find(params[:product_id])
@line_item = @cart.line_items.build(:product => product))
My question is, why do we need to pass the whole product as a parameter? Couldn’t we just pass the :product_id)? Wouldn’t that be more efficient?
I can’t see the constructor of line_item (CoC), so I guess that as a line_item belongs to a product and a cart, if we use the default “build” method we need to pass both of them. Why haven’t we modified the code to pass instead the :cart_id and the :product_id?