当您运行 rails generate controller
时,是否有一种方法可以使用通常的生成器配置来关闭 View 文件夹和操作模板的创建?
我在任何地方都找不到选项和代码 here没有给我任何指示。
无论如何,我们可能会在某个时候为我们的 API 构建我们自己的 Controller /资源生成器,但我很好奇是否有办法同时消除这种烦恼。
最佳答案
这不是一个有据可查的功能,但请尝试在命令中添加 --skip-template-engine
(别名 --no-template-engine
)选项。
rails generate controller foo bar --skip-template-engine
虚拟应用程序演示:
rails g controller my_controller index show --no-template-engine
create app/controllers/my_controller_controller.rb
route get "my_controller/show"
route get "my_controller/index"
invoke test_unit
create test/functional/my_controller_controller_test.rb
invoke helper
create app/helpers/my_controller_helper.rb
invoke test_unit
create test/unit/helpers/my_controller_helper_test.rb
invoke assets
invoke coffee
create app/assets/javascripts/my_controller.js.coffee
invoke scss
create app/assets/stylesheets/my_controller.css.scss
关于ruby-on-rails - 不要在 Rails 生成 Controller 上创建 View 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18406370/