Rails PR: rails/rails#33521
This patch makes it possible to use per-environment credentials (i.e., config/credentials/staging.yml.enc
) in Rails 5.2.
- Drop
backport_rails_six_credentials.rb
andbackport_rails_six_credentials_command.rb
somewhere, for example, into thelib/
folder - Add this line to
config/application.rb
:
# Right after `require "rails"`
require_relative "../lib/backport_rails_six_credentials"
- Add this line to
config/boot.rb
:
# Right after `require 'bundler/setup'`
require_relative "../lib/backport_rails_six_credentials_command"
Now you can call:
$ bundle exec rails credentials:edit -e staging
create config/credentials/staging.key
...
And Rails.application.credentials
now uses env-specific credentials if they're present and master/root credentials otherwise.
Hi Daniel,
The idea is that you only set
RAILS_MASTER_KEY
in production-like environments, where it's impossible to run the app in some other env.Thus, this approach assumes that for local development you use
config/environments/credentials/<env>.key
orconfig/master.key
and not env vars.