Skip to content

Instantly share code, notes, and snippets.

@alexwebgr
Last active August 9, 2021 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexwebgr/c815d02f4c1c148c5181c62676abb918 to your computer and use it in GitHub Desktop.
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
# 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