How to set secret key for Devise in Rails?

Mike_Code_Novice picture Mike_Code_Novice · May 15, 2014 · Viewed 9k times · Source

I added the Devise gem then followed the instructions and ran rails generate devise:install, the result was the following:

/usr/local/rvm/gems/ruby-1.9.3-p194/gems/devise-3.2.4/lib/devise/rails/routes.rb:487:in        `raise_no_secret_key': Devise.secret_key was not set. Please add the following to your Devise initializer: (RuntimeError)

config.secret_key = 'abc123'

Please ensure you restarted your application after installing Devise or setting the key.

How do I 'restart' my application? And how and where do I set the secret key?

Answer

aloucas picture aloucas · Jul 20, 2015

In order to generate a secret run:

bundle exec rake secret

and copy the result from the console to the devise initializer (config/initializers/devise.rb)

config.secret_key = '4fce3c1c860216b8......'