Help us understand the problem. What is going on with this article?

【小ネタ】Rails 5におけるconfig.generatorsの書き方

More than 3 years have passed since last update.

railsのgeneratorの設定を変更したいときに、Rails 4まではapplication.rbに書くことで変更していた。しかし、Rails 5では違う。 application.rb には以下のように書いてある。

application.rb
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

雑に意訳すると、「ここで書いた設定よりも環境ファイルで書かれたことを優先するよ。アプリケーション全体の設定なら、 config/initializers にファイル作るべき。そのディレクトリにおいておけば自動的に読み込んでくれるよ。」とのこと。

ということで参考リンクどおりに下記のようなファイルを作った。

config/initializers/generators.rb
Rails.application.config.generators do |g|
  .
  .
  .

end

参考

Move generator settings to generators.rb · JunichiIto_rails-4-1-rspec-3-0@a85038e

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした