Dave Sanders Dave Sanders - 9 months ago 52
Ruby Question

Don't create view folder on rails generate controller

This is a trivial question, but I'm curious:

Is there a way with the usual generators config to turn OFF the creation of the view folders and action templates when you run a

rails generate controller

I can't find an option anywhere and the code here doesn't show me any pointers.

We are likely going to be building our own controller / resource generators at some point anyway, for our API, but I was curious if there was a way to turn off this annoyance in the meantime.

Answer Source

It's not a well documented feature, but try to add --skip-template-engine (alias --no-template-engine) option to the command.

rails generate controller foo bar --skip-template-engine

demo on a dummy app:

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