Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rails master.key after upgrading to rails 5.2

So I've upgraded an app I'm working on to rails 5.2 and it's crashing on Heroku. I think it's because I don't have a master.key file in my /config folder. I still have the secrets.yml file from the previous rails version. What do I have to do to resolve this issue? Thanks!

error in heroku logs:

2019-01-28T21:07:46.922561+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/aws-sdk-s3-1.30.1/lib/aws-sdk-s3/bucket.rb:684:in `extract_name': Cannot load `Rails.config.active_storage.service`: (ArgumentError)
2019-01-28T21:07:46.922573+00:00 app[web.1]: missing required option :name
like image 256
Rudi Thiel Avatar asked Sep 12 '25 04:09

Rudi Thiel


2 Answers

You have to generate master.key and credentials.yml.enc. To do this, just run the command:

run EDITOR=vim rails credentials:edit

(As editor you can use something else, for example atom or nano).

In opening editor, you can type credentials, and save it. Rails use master.key to encrypt credentials. More you can find here: https://medium.com/cedarcode/rails-5-2-credentials-9b3324851336

To make encrypted credentials work on Heroku, you can copy key from master.key and use it to set up RAILS_MASTER_KEY environemnt variable. You can achieve this by Heroku Dashboard or Heroku CLI, as below:

$ heroku config:set RAILS_MASTER_KEY=`cat config/master.key`
like image 106
barmic Avatar answered Sep 14 '25 18:09

barmic


A couple of things. Speaking from my own personal experience, I've upgraded several Rails apps to 5.2 and I have been able to deploy to Heroku just fine without this feature. So I don't think its that necessarily.

If you could run heroku logs --tail --app <your app name> and show us a stack trace of why your app is failing, that would definitely help.

like image 37
danielricecodes Avatar answered Sep 14 '25 17:09

danielricecodes