Rails 5.1のEncrypted secretsの設定に関して
config.read_encrypted_secrets=true
の設定とパラメータを取得する順番は気をつける必要がある
例えば、application.rb は production.rb より前に読まれるので、 config.read_encrypted_secrets=true
を production.rb で記述していて、かつ、application.rb 内で Rails.application.secrets.*****
等と呼んだ場合、
その設定値は反映されない。
また、それ以外のパラメータも secrets.yml.enc
から読み込まれなくなるので、必ず config.read_encrypted_secrets=true
後に Rails.application.secrets.*
を呼ぶようにすること
https://github.com/rails/rails/issues/28618
The application.rb is read before production.rb. Therefore, can not read encrypted secrets because try to read before setting config.read_encrypted_secrets to true in production.rb.
If you want to use encrypted secrets in application.rb, you need to add config.read_encrypted_secrets = true to application.rb. As following:
config.read_encrypted_secrets = true
config.action_mailer.smtp_settings = {
address: 'smtp.sendgrid.net',
port: 587,
user_name: 'apikey',
password: Rails.application.secrets.sendgrid_api_key,
enable_starttls_auto: true
}