
mert
Agile Web Development with Rails 7: page 120
Hello everyone,
I am relatively new to rails. I am reading AWDWR 7.
I am at page 120, I have some questions and having some problems.
Questions:
-
In
line_item
model we create a relationship toproduct
andcart
models. Do we need an x m
relationship between product and cart models? Because of that we create theline_item
model? -
Also inside the
product
andcart
models we havehas_many :line_items
. Where is these relationships inside our schema.rb? I don’t see any sql relationship? If we don’t have a sql relationship is it good way to create relationships in ruby?
Need help code debugging:
- I think I am having some problem. inside the line_items_controller.rb in the create method at
@line_item = @cart.line_items.build(product: product)
it gives me error. Saying : ActiveModel::MissingAttributeError in LineItemsController#create
can’t write unknown attributeproduct_id
. Any helps solving this problem
Thank you @rubys for this book!
Have a great day!
Mert
Marked As Solved

rubys
It looks like your line_items are missing both a product and a cart. Those should have been added when you generated your scaffold in Iteration D2.
You can add them now with the following:
bin/rails generate migration AddProductAndCartToLineItems product:references cart:belongs_to
Popular Prag Prog topics










Other popular topics









Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /opensuse
- /rust
- /kotlin
- /ruby
- /erlang
- /python
- /clojure
- /react
- /quarkus
- /go
- /vapor
- /v
- /react-native
- /wasm
- /django
- /security
- /nodejs
- /centos
- /rails
- /haskell
- /fable
- /gleam
- /js
- /swift
- /deno
- /assemblyscript
- /tailwind
- /laravel
- /symfony
- /phoenix
- /crystal
- /typescript
- /debian
- /adonisjs
- /julia
- /arch-linux
- /svelte
- /spring
- /flutter
- /preact
- /c-plus-plus
- /actix
- /java
- /angular
- /ocaml
- /zig
- /kubuntu
- /scala
- /zotonic
- /vim
- /rocky
- /lisp
- /keyboards
- /html
- /nim
- /emacs
- /vuejs
- /elm
- /nerves