Per Environment Rails 6 Credentials

Categories: rails


Rails 6 introduced support for per environment credentials. Pull request can be found here

To generate a new credentials config

# bin/rails credentials:edit -e <environment>
bin/rails credentials:edit -e production

This will create config/credentials/production.yml.enc and config/credentials/production.key

Now if your current environment is production it will look for the value in config/credentials/production.yml.enc. If it’s not found, it will default to config/credentials.yml.enc

To make changes to the credentials file run

# bin/rails credentials:edit will edit the default config
bin/rails credentials:edit -e <environment>