What is the Rails (>=3.1) generator syntax for creating a subclass model / scaffold?

梦想的初衷 提交于 2019-12-23 08:36:32

问题


What is the command line syntax for generating a subclass model or scaffold in Rails?

rails g model Mysubclass my_field:string ....

How do I specify the parent class?


回答1:


You can use "--parent=ParentClass".

Example:

1) Create a parent class "User".

rails g scaffold User login:string

2) Create a child class "Teacher".

rails g scaffold Teacher url:string --parent=User

But remember: you still need to create migrations(adding columns in datatables) and change views(adding fields in forms).




回答2:


Just as Ruby syntax:

rails g model Parent::Children


来源:https://stackoverflow.com/questions/8792290/what-is-the-rails-3-1-generator-syntax-for-creating-a-subclass-model-scaff

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!