我读的帮助和尝试下面的命令跳过一代的测试,资产和辅助文件
$ bin/rails generate controller home index --helper false --assets false --controller-specs false --view-specs false
create- app/controllers/home_controller.rb
route get "home/index"
invoke erb
create app/views/home
create app/views/home/index.html.erb
invoke rspec
error false [not found]
error false [not found]
正如你可能输出高于这个工程及只注意到controller, routes
和views
产生的。 但是,随着最后两行很有意思:
error false [not found]
error false [not found]
显然,轨道似乎并不喜欢--option-name false
语法。 所以这此错误,因为我使用了错误的语法? 如果是的话,那么什么是正确的方法是什么? 谢谢
尝试使用--no-
其次optionname
:
rails generate controller home index --no-helper --no-assets --no-controller-specs --no-view-specs
如果你想每次运行生成命令时更改默认的行为,你可以配置你想在application.rb中文件的默认值-看我如何确保Rails不产生意见和助手规范测试? 。
要关闭,而无需添加选项:
# application.rb
config.generators.assets = false
config.generators.helper = false
它的作用只是API的应用程序将不需要javascript
, stylesheet
, views
, helpers
。 在发电机/支架跳过这些文件中添加下面的代码块application.rb
#to skip assets, scaffolds.css, test framework, helpers, view
config.generators do |g|
g.template_engine nil #to skip views
g.test_framework nil #to skip test framework
g.assets false
g.helper false
g.stylesheets false
end
检查链接了解更多详细信息发电机
更简洁:
rails g controller home index --no-assets --no-test-framework
文章来源: What is the syntax to skip creating tests, assets & helpers when running `rails generate controller`?