Rails: How to fix “Missing secret_key_base for 'production' environment”

前端 未结 8 1841
野趣味
野趣味 2020-12-15 16:33

I simply can\'t get past the message:

Missing `secret_key_base` for \'production\' environment, set this string with `rails credentials:edit` (ArgumentError)         


        
8条回答
  •  萌比男神i
    2020-12-15 16:50

    I experienced this same issue when working on a Rails 5.2 application in production.

    I already had other things set up. The problem for me was not that the secret_key_base wasn't set properly, it was rather because of the Passing the environment's name as a regular argument like below is deprecated

    rails c RAILS_ENV=production
    

    If you look at your error log generated closely from its top you will see this:

    DEPRECATION WARNING: Passing the environment's name as a regular argument is deprecated and will be removed in the next Rails version. Please, use the -e option instead. (called from at bin/rails:9)

    To run the rails console in a different environment, use the -e option like this:

    rails console -e production
    

    Note: Setting the secret_key_base in the secrets.yml file is not safe, as it's not a secure way of storing the key, please use the encrypted credential.yml file and the master key to decrypt it.

    That's all.

    I hope this helps

提交回复
热议问题