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!
My project has got Rails 5.2.3.
I made as such as you proposed above, but I came across at this:
Go to debug and see:
[2] pry(main)> Rails.application.config.credentials => {:content_path=>"/app/config/credentials/development.yml.enc", :key_path=>"/app/config/credentials/development.key"}
I made a little fix in your code at
/lib/backport_rails_six_credentials.rb#15
as:@credentials.content_path = Pathname default_credentials_content_path
and it works!Have you ideas, why it does not work without my fix? Thanks :)