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

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

johnp
Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’. In particula...
New
jamis
The following is cross-posted from the original Ray Tracer Challenge forum, from a post by garfieldnate. I’m cross-posting it so that the...
New
sdmoralesma
Title: Web Development with Clojure, Third Edition - migrations/create not working: p159 When I execute the command: user=> (create-...
New
rmurray10127
Title: Intuitive Python: docker run… denied error (page 2) Attempted to run the docker command in both CLI and Powershell PS C:\Users\r...
New
jeremyhuiskamp
Title: Web Development with Clojure, Third Edition, vB17.0 (p9) The create table guestbook syntax suggested doesn’t seem to be accepted ...
New
curtosis
Running mix deps.get in the sensor_hub directory fails with the following error: ** (Mix) No SSH public keys found in ~/.ssh. An ssh aut...
New
jskubick
I’m running Android Studio “Arctic Fox” 2020.3.1 Patch 2, and I’m embarrassed to admit that I only made it to page 8 before running into ...
New
akraut
The markup used to display the uploaded image results in a Phoenix.LiveView.HTMLTokenizer.ParseError error. lib/pento_web/live/product_l...
New
gorkaio
root_layout: {PentoWeb.LayoutView, :root}, This results in the following following error: no “root” html template defined for PentoWeb...
New
roadbike
From page 13: On Python 3.7, you can install the libraries with pip by running these commands inside a Python venv using Visual Studio ...
New

Other popular topics Top

AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
New
Exadra37
On modern versions of macOS, you simply can’t power on your computer, launch a text editor or eBook reader, and write or read, without a ...
New
Rainer
Not sure if following fits exactly this thread, or if we should have a hobby thread… For many years I’m designing and building model air...
New
DevotionGeo
The V Programming Language Simple language for building maintainable programs V is already mentioned couple of times in the forum, but I...
New
OvermindDL1
Woooooooo! This is such a huge release for it, and 2 years incoming! In short, the library is now using an updated hyper backend (not j...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
New
New

Latest in PragProg

View all threads ❯