Devise Secret Key was not set

前端 未结 16 1166
别那么骄傲
别那么骄傲 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:26

    Ran into the same trouble with Rails 5.2.0 and Devise 4.4.1

    Drop the following into /config/initializers/devise.rb

    config.secret_key = Rails.application.credentials.secret_key_base
    
    0 讨论(0)
  • 2020-11-27 15:27

    I has same issue. The problem was caused by these lines in routes.rb:

    devise_for :users, :skip => [:registrations]                                                   
    as :user do
      get 'users/edit' => 'devise/registrations#edit', :as => 'edit_user_registration'              
      put 'users' => 'devise/registrations#update', :as => 'user_registration'                      
      get '/users/sign_out' => 'devise/sessions#destroy'                                            
    end
    

    I commented them and after that i run:

    $ rails generate devise:install
    

    And it has evaluated perfectly. And after that I uncommented routes.

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

    As of Devise 3.2.3 for Rails 4+ applications the key setting location defaults to YourAppName::Application.config.secret_key_base found in config/initializers/secret_token.rb

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

    Well, I have been following this post and tried almost everything here. I have added the key to devise.rb. But I was still getting the same error.

    Maybe a stupid answer, but all I had to do was to push the devise.rb key to the repository.

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

    Fix:

    1. In the production server:

      sudo -H nano /etc/environment
      
    2. Then in the file add:

      export SECRET_KEY_BASE="yourkey"
      export DEMO03_DATABASE_PASSWORD="yourpass"
      

      to set this permanently, and system wide (all users, all processes) add set variable

    3. In the local project devise.rb file:

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

    Technical details:

    • Ubuntu 16.04
    • Devise (4.2.0)
    • rails 5.0.1
    • capistrano (3.7.1)
    0 讨论(0)
  • 2020-11-27 15:30

    I cloned my repository onto a new machine from git. The

    config/secrets.yml 
    

    file was on my .gitignore list, so that file didn't exist, and Devise doesn't create the file.

    I added the file, then re-ran

    rails generate devise MODEL
    

    and it worked.

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