Rails: pass has_many or attribute_to attribute in the generate command

I am trying to make a scaffold, but I want to pass the has_many attribute to the generate command as follows:

rails generate scaffold grade name:string {has_many :sections} 

This generates a broken model:

 class Grade < ActiveRecord::Base attr_accessible :, :name, :{has_many end 

instead of what i need:

 class Grade < ActiveRecord::Base attr_accessible :name has_many :sections end 

How to pass a relation attribute to the generate command?

+4
source share
1 answer

Currently, the only thing you can do with scaffolding is to add a link to the model you want to belong to: class_to

 rails generate model Sections name:string grade:references 

There are ways to generate relationships, but these are not standard Rails forests. There are many options, for example:

Ubiquo_scaffold

+11
source

Source: https://habr.com/ru/post/1442036/


All Articles