4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Railsアプリケーション全体のジェネレーターの設定変更方法

Posted at

Railsアプリケーション全体のジェネレータの設定変更方法について、調べながら学習したのでここにアウトプットさせていただきます。

  • 開発環境
    • Ruby 2.6.4
    • Rails 5.2.3

設定方法

Railsアプリ全体のジェネレーターの設定を変更するには、config/application.rbファイルに設定コードを追記してあげると変更する事ができます。

application.rbファイルのclass Application < Rails::Applicationの記述下に、

config.generators do |g|
end

以上のコードを追記し、config.generators do |g| 〜 endの間に設定コードを追記します。

config.generators do |g|
 #ここに設定コードを追記する
end

今回はRails generate controllerでファイルを自動生成する際に、asset, helper, testファイル, ルーティングが生成されない様に制限を設けたかったので、以下の4行のコードを追記しました。

config.generators do |g|
 g.assets false #assetsを生成しない
 g.helper false #helperを生成しない
 g.test_framework false #testファイルを生成しない
 g.skip_routes true 	#ルーティングを生成しない
end

これでRailsアプリケーション全体のジェネレーターの設定を変更する設定ができました。

あとはこの状態でrails g controller user show の様なジェネレーターコマンドを入力すると、

スクリーンショット 2020-11-23 21.11.00.png

上記の様に必要なディレクトリやファイルだけを生成する事ができます。

終わり

以上でアウトプットを終わります。
最後まで読んでいただきありがとうございました。
少しでもお役に立てれる内容であれば幸いです。

4
5
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
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?