简体   繁体   中英

ruby on rails: heroku: Missing `secret_key_base` for 'production' environment

I added the key into heroku config var, but I'm still getting the error.

Is this the correct way? I ignored secrets.yml as I read from other sources that its not a good idea to push this to the public.

in the heroku config var:

[key] SECRET_KEY_BASE
[value] 3280570382948240938

in secrets.yml

production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

What am I still doing wrong?

Furthermore, if I put my secret keys into heroku's config variable, don't other developers get to see this too? So, isn't that still kind of public? I've always wondered this concept.

you can set environment variable with heroku config

first generate secret key with run below command on terminal

rake secret

Now use that key on below command

heroku config:set SECRET_KEY_BASE='put here new generated key'

you can refer this link for more refference

https://devcenter.heroku.com/articles/config-vars

here is a fool-proof way to set the secret key base with heroku:

heroku config:set SECRET_KEY_BASE=$(rake secret)

you can see it with heroku config:get SECRET_KEY_BASE

and check that rails picks it up with Rails.application.secret_key_base (in heroku run rails console for instance)

I had the same issue today, but for me the solution was a bit different. I realized that in my local environment, I had been using:

Rails.application.secrets.secret_key_base

but for Heroku, instead use:

Rails.application.secret_key_base

^This worked in my local environment as well. Not sure what the extra .secrets is for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM