Topic: has_many :through question
I am a new student of Rails, which has been great so far. I'm now practicing database connection with Rails, and have a rather simple question regarding has_many :through. I've looked at some past posts, but they only cover the model-design, not the accompanying controller actions.
Basically, I want to create the simplest possible shopping cart.
xitems has two columns: id, name
xlists has two columns: id, title
I'm bridging the two via xtracks which has three columns: xlist_id, xitem_id, xcount (all ints)
A view for xlists with a text-field for title, a drop-down containing the names of all xitems, and a text-field for specifying the count (how many of the selected xitem the user wants).
Create a scaffold for xlist.
Then, apply "has_many :through", as follows:
class Xitem < ActiveRecord::Base
has_many :xlists, :through => :xtracks
class Xlist < ActiveRecord::Base
has_many :xitems, :through => :xtracks
class Xtrack < ActiveRecord::Base
Since I've been using the scaffold generator until now for any kind of CRUD, I'm not sure how to implement CRUD manually via has_many :through.
Since I've put the default scaffold for xlist, when I create a new entry, it only allows me to edit xlist's columns, not xitem's. So what do I have to add to the xlist controller to relate the three tables? That is, how do I go about storing the data in a linked manner?
Last edited by tabletennis001 (2007-02-09 22:36:38)