Last active
August 9, 2021 11:44
-
-
Save alexwebgr/c815d02f4c1c148c5181c62676abb918 to your computer and use it in GitHub Desktop.
How to generate, manage and use env-specific encrypted credentials in rails 5.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# generate and edit env-specific encrypted credentials | |
EDITOR=nano bin/rails encrypted:edit config/development.yml.enc --key config/development.key | |
# override credentials in application.rb | |
def credentials | |
encrypted( | |
"config/#{Rails.env.downcase}.yml.enc", | |
key_path: "config/#{Rails.env.downcase}.key" | |
) | |
end | |
# use in the application like this | |
database: <%= Rails.application.credentials.database %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment