LoginSignup
13
16

More than 3 years have passed since last update.

「rails generate controller(rails g controller)」をする時に無駄なhelperやassetsを作らない方法

Last updated at Posted at 2018-10-14

「rails generate controller」 で controller を生成すると、必要の無い helper、 coffee、stylesheetファイルが一緒に生成されて、それを後から消すのって非常に面倒ですよね。
かといって

$ rails generate controller users --no-helper --no-assets

のようにコントローラを作るたびにオプションを後ろにつけるのは面倒。しかもこんなの絶対いつか忘れます。(笑)

でも、実はオプションを付け足さずにデフォルトでhelperなどを付け足さないコードがあるんです!
それがこれです。

config/application.rb
module App
  class Application < Rails::Application
   config.generators do |g|
     g.helper false
     g.assets false
   end
  end
end

こんな風に「rails generate controller」をする時に生成したくないものがあったら、config/application.rbにコードを書いておく!

これでデフォルトでhelperやassetsが生成されなくなりました:thumbsup:
是非、試してみてください!!

13
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
16