Code shows:
@line_item = @cart.line_items.build(product: product)
This produces an error of " * Product must exist" when you press the “Add to Cart” button.
However, if I change the line to add “.id” to product, then it works as expected:
@line_item = @cart.line_items.build(product_id: product.id)