简体   繁体   English

导轨会生成支架,但会阻止生成模型文件

[英]rails generate scaffold but prevent the model file from being generated

I have looked over the documentation at rails generate scaffold -h but am still stumped. 我在rails generate scaffold -h查看了文档,但是仍然很困惑。 I want to create all the files from the scaffold generator except the model file. 我想从脚手架生成器创建所有文件, 除了模型文件。

Example: 例:

rails generate scaffold User --no-model

This as it is does not work but what I would like to happen is that the user.rb file is prevented from being created within the models directory. 这是行不通的,但是我想发生的事情是禁止在models目录中创建user.rb文件。

Figured it out! 弄清楚了! You just need to include --skip to tell rails that for any conflicting files to just ignore creating those files. 您只需要包括--skip即可告知Rails,任何有冲突的文件都将忽略创建这些文件。

Example : say I already have the file user.rb inside my models directory: 示例 :说我的模型目录中已经有文件user.rb

rails generate scaffold User --skip

With the --skip option rails knows to skip creating the user.rb file, as well as all other already existing files that the scaffold command would generate for this resource. 使用--skip选项,rails可以跳过创建user.rb文件以及scaffold命令将为此资源生成的所有其他现有文件的过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM