Rails: ActiveSupport::MessageEncryptor::InvalidMessage

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 them with this:

rails credentials:edit --wait

While the credentials are open, note the master.key string, and then close the editor.

If you have not set the editor, you may need to do

EDITOR="your_editor_name --wait" bin/rails credentials:edit

The file master.key should be ignored by your version control because it is the key rails uses 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 set it to the value of master.key.

Now to access the environments variables that you defined on your .enc file you must access them 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
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)