First try to provide a generator for Rails 3.x that scaffolds a has_many :through relation. See the stackoverflow question for some context.
To use the generator for "has_many :through", you have to do the following steps:
- Install the generator by copying the directory "scaffold_hmt" to your rails application in the directory 'lib/generators'.
- Start the generator by calling from your home directory of the application:
rails g scaffold_htm Model1 Model2
. - The generator will generate or change the following files:
- Migration
<timestamp>_create_<model1>_<model2>.rb
- Model file
<model1>s_<model2>.rb
- Insert into
<model1>.rb
and<model2>.rb
thehas_many :through
relations.
- Migration
The mandatory arguments for the generator are the model names. They will be sorted alphabetically if necessary. If a third argument (the join model name) is given, it will be used, if not, it will be computed:
join table name: `<model1>s_<model2>s`
join model name: `<Model1>s<Model2>`