4

我正在尝试制作脚手架,但想将 has_many 属性传递给生成命令,如下所示:

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

这会生成损坏的模型:

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

而不是我需要的:

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

如何将关系属性传递给生成命令?

4

1 回答 1

11

目前,您可以使用脚手架做的唯一事情是在您想要的模型中添加一个引用 belongs_to

rails generate model Sections name:string grade:references

有一些方法可以生成关系,但它不是 Rails 标准的脚手架。有很多选择可以做到这一点:

Ubiquo_Scaffold

于 2012-10-25T13:08:10.033 回答