みつのーと

(*・ω・)ノシ

Rails4のgenerate controllerでviewやassetsを生成しないオプション

rails g controllerしたときに「Asssets周りは要らないんだよなー」ってケースが割りとあった。 -hでヘルプみてもピンと来なかったんだけど、ググッてみたらちゃんと先人の方々が書いてくれていた。

各オプションとその結果の備忘録。

オプション無し

% rails generate controller piyo
Running via Spring preloader in process 3152
      create  app/controllers/piyo_controller.rb
      invoke  erb
       exist    app/views/piyo
      invoke  test_unit
      create    test/controllers/piyo_controller_test.rb
      invoke  helper
      create    app/helpers/piyo_helper.rb
      invoke    test_unit
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/piyo.coffee
      invoke    scss
      create      app/assets/stylesheets/piyo.scss

controllerだけでいいとき: --no-assets --no-helper --skip-template-engine

% rails generate controller piyo --no-assets --no-helper --skip-template-engine
Running via Spring preloader in process 5517
      create  app/controllers/piyo_controller.rb
      invoke  test_unit
      create    test/controllers/piyo_controller_test.rb

asset要らないとき: --no-assets

% rails generate controller piyo --no-assets
Running via Spring preloader in process 5187
      create  app/controllers/piyo_controller.rb
      invoke  erb
      create    app/views/piyo
      invoke  test_unit
      create    test/controllers/piyo_controller_test.rb
      invoke  helper
      create    app/helpers/piyo_helper.rb
      invoke    test_unit

helper要らないとき: --no-helper

% rails generate controller piyo --no-helper
Running via Spring preloader in process 5287
      create  app/controllers/piyo_controller.rb
      invoke  erb
      create    app/views/piyo
      invoke  test_unit
      create    test/controllers/piyo_controller_test.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/piyo.coffee
      invoke    scss
      create      app/assets/stylesheets/piyo.scss

view要らないとき: --skip-template-engine

% rails generate controller piyo --skip-template-engine
Running via Spring preloader in process 5425
      create  app/controllers/piyo_controller.rb
      invoke  test_unit
      create    test/controllers/piyo_controller_test.rb
      invoke  helper
      create    app/helpers/piyo_helper.rb
      invoke    test_unit
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/piyo.coffee
      invoke    scss
      create      app/assets/stylesheets/piyo.scss

テストから逃げたいとき: --no-test-framework

% rails g controller piyo --no-test-framework
Running via Spring preloader in process 5795
      create  app/controllers/piyo_controller.rb
      invoke  erb
      create    app/views/piyo
      invoke  helper
      create    app/helpers/piyo_helper.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/piyo.coffee
      invoke    scss
      create      app/assets/stylesheets/piyo.scss

Rails便利ですね、レールに沿って進むのは意外と難しいですが。