Rails credentials
Generate Rails secret
$> bundle exec rails secret
To generate/edit rails credentials
EDITOR=vim rails credentials:edit
To generate/edit rails credentials for production
EDITOR=vim rails credentials:edit --environment production
To generate/edit rails credentials for staging
EDITOR=vim rails credentials:edit --environment staging
Access these variables inside codebase
Development
$ rails c
> Rails.application.credentials.config
#=> {:aws=>{:access_key_id=>"123", :secret_access_key=>"345"} }}
> Rails.application.credentials.aws[:access_key_id]
#=> "123"
Production
$ RAILS_ENV=production rails c
> Rails.application.credentials.config
#=> {:aws=>{:access_key_id=>"123", :secret_access_key=>"456xx"}}
> Rails.application.credentials.aws[:access_key_id]
#=> "123"
In case of docker-compose
$> docker-compose run --rm -e EDITOR=vim <service-name> bin/rails credentials:edit
Related Notes:
This is a sapling 🌱 in my digital garden 🏡.
Notes mentioning this note
Rails Notes
Related Notes:
[[Rails Docker]]
[[Rails Credentials]]
Rails 7 features
Ruby Toolbox
Ruby Regex