
bunnahabhain
Agile Web Development with Rails 8_B6.0(page 126)
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)
Marked As Solved

bunnahabhain
I have resolved the issue by recreating the depot app from the beginning. I had been avoiding doing so as I was following along with each beta release of the book, and had been building upon the chapters that I had already completed.
I have a feeling that it might have simply been an issue with a bad record in the database, as I recall pressing the “new product” button before completing the code that went along with the button. Unfortunately, I had dropped and recreated the database before I thought to take a look at it.
Please consider this issue closed. Thanks!
Popular Pragmatic Bookshelf topics










Other popular topics









Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /rails
- /js
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /ash
- /vscode
- /opensuse
- /centos
- /php
- /deepseek
- /html
- /scala
- /zig
- /debian
- /nixos
- /lisp
- /agda
- /sublime-text
- /react-native
- /textmate
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /django
- /manjaro
- /spring
- /diversity
- /lua
- /nodejs
- /julia
- /slackware
- /c
- /neovim