Home > Software engineering >  :MissingKeyError in rails 2.5.5
:MissingKeyError in rails 2.5.5

Time:12-23

I'm working with ruby 2.5.5 and I'm starting the server like so:

RAILS_MASTER_KEY=[MY_KEY] RAILS_ENV=staging MY_DATABASE_PASSWORD=[MY_PW] bin/rails server -b 0.0.0.0

that works, now I want to generate migrations like so:

RAILS_MASTER_KEY=[MY_KEY] RAILS_ENV=staging MY_DATABASE_PASSWORD=[MY_PW] bin/rails generate migration CreateJoinTableMyTable column1 foreignKey

And I get the following error:

/path/to/.rvm/gems/ruby-2.5.5/gems/activesupport-5.2.3/lib/active_support/encrypted_file.rb:96:in `handle_missing_key': Missing encryption key to decrypt file with. Ask your team for your master key and write it to /Users/BaxterStockman/empiric/hyperion-backend-webapp/config/master.key or put it in the ENV['RAILS_MASTER_KEY']. (ActiveSupport::EncryptedFile::MissingKeyError)

I also wrote the RAILS_MASTER_KEY into ~/.bashrc and reload the profile but that didn't do anything.

Anyone an idea why this error gets thrown?

CodePudding user response:

What's the rails version? It shows you the error that you should have a file config/master.key in app folder. It's required to decrypt the credentials.yml.enc.

Just add that file by asking your colleagues or if you don't have one, generate via

EDITOR="code --wait" rails credentials:edit

You might google which EDITOR= instead of code you'd use as I don't know that. Just make sure the editor won't be closed immediately, that's why for VSCode I had to use --wait argument.

Afterwards, you might place RAILS_MASTER_KEY in credentials.yml.enc.

Since Rails 5.2 credentials file appeared, so you don't need to store keys in operating system's ENV variables.

  • Related