Reputation: 6639
Rails 7
I am running into some issues using [Rails.env.to_sym]. Some config files understand it, and some do not.
Doing some research, it seems as if I can generate different credentials files, for each runtime environment. For instance:
rails credentials:edit --environment development
rails credentials:edit --environment test
Does this mean that Rails will pick the appropriate credentials file, based on the rails environment setting (test, development, etc.)?
Upvotes: 2
Views: 3931
Reputation: 557
That’s correct — the main credentials file (credentials.yml.enc
) is overwritten by environment-specific files.
If you run bin/rails credentials:edit -h
from the command line, you’ll see this:
=== Environment Specific Credentials
The `credentials` command supports passing an `--environment` option to create an environment specific override. That override will take precedence over the global `config/credentials.yml.enc` file when running in that environment. So:
bin/rails credentials:edit --environment development
will create `config/credentials/development.yml.enc` with the corresponding encryption key in `config/credentials/development.key` if the credentials file doesn't exist.
One tiny gotcha for me — I ran into an error trying to generate environment-specific credentials file (part of error below):
`binwrite': No such file or directory @ rb_sysopen - config/credentials/test.yml.enc.tmp
My fix was creating the empty folder first (config/credentials
) and then re-running command (e.g., bin/rails credentials:edit --environment test
)
Upvotes: 5