I simply can't get past the message:
Missing `secret_key_base` for 'production' environment, set this string with `rails credentials:edit` (ArgumentError)
I have Rails 5.2.0, and ran
EDITOR=vim rails credentials:edit
and inside:
production: secret_key_base: xxxxxxxxxxxxxxxxxxxxxxx
Save and, in the terminal:
RAILS_ENV=production rails c
Am I missing something? I've restarted the server and got the same issue, but have no issue in development mode.
secret_key_base is used to encrypt and sign session.
Your text editor will open an unencrypted version of your credentials. If you don't have EDITOR set, you can run EDITOR=vi bin/rails credentials:edit or use your favorite text editor. After saving the file, the encrypted version will be saved to config/credentials. yml.
The key used to encrypt credentials, called the Rails master key, is automatically generated when you create a new Rails app or when you run bin/rails credentials:edit . If you like to create a new key, you can run bin/rails runner 'puts ActiveSupport::EncryptedFile.generate_key'
Keep default the secrets.yml
file
# config/secrets.yml production: secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> aws_secret: abcde some_password: abcdex development: secret_key_base: static_secret_key aws_secret: abcde test: secret_key_base: static_test_secret_key #not_indented: key for all env in once secret_key_base: global_key_for_all_env
RAILS_ENV=production SECRET_KEY_BASE=production_test_key rails c
If using Rails 5.2.0, add to production env below, check this LINK
config.require_master_key = true #config/environments/production.rb
Rails 5.2.0 requires an extra stage for the production environment:
config.require_master_key = true # in config/environments/production.rb
Without it, Rails still falls back to the legacy secret.yml
mechanism (for now).
Engine Yard's Christopher Rigor has written a concise post on it. The relevant piece:
Reading the Credentials
If you want to use the credentials in the production environment, add the following to
config/environments/production.rb
config.require_master_key = true
A good read to also see up and down sides.
Note: As @TomDogg found out, Rails 5.2.1 seems again different, so this answer may only apply to 5.2.0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With