Devise Secret Key was not set

前端 未结 16 1164
别那么骄傲
别那么骄傲 2020-11-27 14:53

I am developing a Rails 4 app using the Active Admin gem for the administration back end. Active Admin in turn uses Devise for user authentication. Now, when I try to deploy

相关标签:
16条回答
  • 2020-11-27 15:10

    In config/initializers/devise.rb I put:

    config.secret_key = ENV["SECRET_KEY_BASE"] if Rails.env.production?
    

    Because if you put:

    $ heroku config
    

    You'll see a secret_key_base for the mode production.

    0 讨论(0)
  • 2020-11-27 15:11

    I ran bundle update this morning and started getting the same error.

    I added it as a line in config/initializers/devise.rb and the error was fixed.

    This seems to be the commit which introduced it.

    0 讨论(0)
  • 2020-11-27 15:11

    I do not know right solution but it's working. You can try it. I was cloned my project from my GitLab account and when I run in my local server, I have an error Message:

    rake aborted! Devise.secret_key was not set. Please add the following to your Devise initializer: config.secret_key = '-- secret key --'

    Open config/initializers/devise.rb and add this line

    config.secret_key = '<%= ENV["SECRET_KEY_BASE"] %>'

    This code line is solved my problem.

    0 讨论(0)
  • 2020-11-27 15:15

    Could it be, that you did not run rails g devise:install?

    Running rails generate devise User without the previous command does cause this problem.

    0 讨论(0)
  • 2020-11-27 15:17

    Check if your config\initializers\secret_token.rb has:

    YourAppName::Application.config.secret_token
    

    It should be:

    YourAppName::Application.config.secret_key_base
    
    0 讨论(0)
  • 2020-11-27 15:19

    This solved my problem:

    Add the code below to your config/initializers/devise.rb file.

    config.secret_key = '-- secret key --' 
    

    Replace '-- secret key--' with your own key. I recommend storing it in an ENV variable for security purpose.

    0 讨论(0)
提交回复
热议问题