Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: pass has_many or belongs_to attribute in 'generate' command

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

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

This generates the 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 can i pass a relationship attribute to the generate command?

like image 510
Tom Avatar asked Dec 20 '22 14:12

Tom


1 Answers

Currently the only thing that you can do with scaffolding is adding a reference in the model you want the belongs_to

rails generate model Sections name:string grade:references

There are ways to generate with relations, but it is not Rails standard scaffolding. There are a lot of options to do that like:

Ubiquo_Scaffold

like image 74
felipeclopes Avatar answered Dec 23 '22 04:12

felipeclopes