mert

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 to product and cart models. Do we need a n x m relationship between product and cart models? Because of that we create the line_item model?

  • Also inside the product and cart models we have has_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 attribute product_id. Any helps solving this problem

Thank you @rubys for this book!

Have a great day!

Mert

0 838 3

Marked As Solved

rubys

rubys

Author of Agile Web Development With Rails

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 Top

jimschubert
In Chapter 3, the source for index introduces Config on page 31, followed by more code including tests; Config isn’t introduced until pag...
8 1308 3
New
herminiotorres
Hi! I know not the intentions behind this narrative when called, on page XI: mount() |> handle_event() |> render() but the correc...
3 1296 17
New
gilesdotcodes
In case this helps anyone, I’ve had issues setting up the rails source code. Here were the solutions: In Gemfile, change gem 'rails' t...
3 1273 2
New
New
Chrichton
Dear Sophie. I tried to do the “Authorization” exercise and have two questions: When trying to plug in an email-service, I found the ...
1 1178 3
New
leonW
I ran this command after installing the sample application: $ cards add do something --owner Brian And got a file not found error: Fil...
5 4327 7
New
dsmith42
Hey there, I’m enjoying this book and have learned a few things alredayd. However, in Chapter 4 I believe we are meant to see the “>...
0 1896 3
New
akraut
The markup used to display the uploaded image results in a Phoenix.LiveView.HTMLTokenizer.ParseError error. lib/pento_web/live/product_l...
2 2080 9
New
bjnord
Hello @herbert ! Trying to get the very first “Hello, Bracket Terminal!" example to run (p. 53). I develop on an Amazon EC2 instance runn...
0 1115 2
New
redconfetti
Docker-Machine became part of the Docker Toolbox, which was deprecated in 2020, long after Docker Desktop supported Docker Engine nativel...
0 893 0
New

Other popular topics Top

Devtalk
Hello Devtalk World! Please let us know a little about who you are and where you’re from :nerd_face:
476 5517 111
New
siddhant3030
I’m thinking of buying a monitor that I can rotate to use as a vertical monitor? Also, I want to know if someone is using it for program...
51 4063 20
New
AstonJ
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
105 4397 51
New
AstonJ
Thanks to @foxtrottwist’s and @Tomas’s posts in this thread: Poll: Which code editor do you use? I bought Onivim! :nerd_face: https://on...
88 5051 33
New
AstonJ
Just done a fresh install of macOS Big Sur and on installing Erlang I am getting: asdf install erlang 23.1.2 Configure failed. checking ...
10 5353 8
New
PragmaticBookshelf
Author Spotlight James Stanier @jstanier James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
29 3856 12
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
15 4338 2
New
New
First poster: joeb
The File System Access API with Origin Private File System. WebKit supports new API that makes it possible for web apps to create, open,...
43 2750 22
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File > New Rule: And select Deny, O...
5 7110 4
New