How to set a secret key for Devise in Rails?

I added Geme Devise and then followed the instructions and ran rails generate devise:install , the result was as follows:

 /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 the application? And how and where can I set the secret key?

+6
source share
2 answers

To create a secret run:

 bundle exec rake secret 

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

 config.secret_key = '4fce3c1c860216b8......' 
+12
source

You need to add a line to your config/initializers/devise.rb to set the secret key (replace the example below with a more secure and random key):

  config.secret_key = 'yoursecretkey' 

After that, just stop your Rails server and start it again. Also see This fooobar.com/questions/66330 / ....

+1
source

Source: https://habr.com/ru/post/969354/


All Articles