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
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
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.
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
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.
Fix:
In the production server:
sudo -H nano /etc/environment
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
In the local project devise.rb
file:
config.secret_key = ENV["SECRET_KEY_BASE"] if Rails.env.production?
Technical details:
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.