Missing `secret_token` and `secret_key_base` for &

2019-04-29 12:40发布

问题:

I see all answers for this solution but no worked for me.

1 - My configuration deploy is equal this tutorial by DigitalOcean (Capistrano 3, Nginx, and Puma), with deploy success, i have error in my web:

An unhandled lowlevel error occurred. The application logs may have details.

In log:

Rack app error: #< RuntimeError: Missing secret_token and secret_key_base for 'production' environment, set these values in config/secrets.yml>

2 - In my droplet or VPN, I created variable with a key (rake secret) in file ./bashrc

export SECRET_KEY_BASE=XXXXXX

The file /config/secrets.yml is default

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

With this env variable, i checked than this worked (echo $SECRET_KEY_BASE or printenv | grep SECRET_KEY_BASE)

3 - After Puma and Nginx is restarted and this error not is solved, i not know what is best way to check or debug this error.

Does this tutorial does not work with this solution?

回答1:

This is the proper way of handing capistrano env of rails using dotenv-rails gem. The method to use capistrano and env rails in explained in Using Environment Variables in Rails, Heroku, Capistrano