Help me please, I\'ve finished 11 chapters of the rails tutorial, deployed my app to heroku (locally it worked perfectly) and it crashing all time. I\'m using rails 5.2.2 Af
I had this issue when working on a Rails 6 application in Ubuntu 20.04.
The issue was that I was setting/specifying a wrong RAILS_MASTER_KEY
environment variable in my .env
files in development (.env
, .env.development
). I just wanted to use it as a placeholder temporarily since I did not need it in my development environment.
This was then throwing the error below when I run a rails command, say rails generate uploader ProductImage
:
`rescue in _decrypt': ActiveSupport::MessageEncry ptor::InvalidMessage (ActiveSupport::MessageEncryptor::InvalidMessage)
And even when I try generating a new master.key
and the credentials.yml.enc
files using rails credentials:edit
or EDITOR="code --wait" bin/rails credentials:edit
it throws the error below:
key=': key must be 16 bytes (ArgumentError)
Here's how to fix it:
What you have to do is to either provide the correct RAILS_MASTER_KEY
environment variable in the .env
file(s) or comment out the RAILS_MASTER_KEY
environment variable if you are not using it.
That's it.
I hope this helps
rm -rf config/credentials.yml.enc
EDITOR="mate --wait" bin/rails credentials:edit
Hope it's helpful.
You need to ask for the master key to you project leader / team leader / coworkers.
With that long key like 3823729sdad29323832idsd you copy it and paste it the master.key file under config folder.
That solve the issue.
Here are the docs for environmental security on rails https://guides.rubyonrails.org/security.html#environmental-security
In your case, you should have these files
config/master.key
config/credentials.yml.enc
Delete those files and then you can generate with this:
rails credentials:edit
Now the file master.key is ignored by your version control because it is the key rails use to decrypt the .enc, just commit your credentials.yml.enc and push it to heroku.
For master.key on heroku you can define the environment variable RAILS_MASTER_KEY on your heroku app and put the value of master.key on it.
Now to access the environments variables that you defined on your .enc file you must access through Rails.application.credentials
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => Rails.application.credentials.SENDGRID_USERNAME,
:password => Rails.application.credentials.SENDGRID_PASSWORD,
:domain => 'heroku.com',
:enable_starttls_auto => true
}
the only way for me was to renew my master key.
This post help me https://github.com/rails/rails/issues/32718