0

I'm trying to install the devise gem and when I do the

$ rails generate devise: install

I get the following error:

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

  config.secret_key = '964705f2d08f9196c511948baa14a1ef2ba7693b6eb326f9b177a1377d2c8487aab5736798e4bae6286eb0e36298eac3bceff31be5c357d356db8a22edd04a4d'

Please ensure you restarted your application after installing Devise or setting the key.
    from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/devise-3.1.2/lib/devise/rails/routes.rb:195:in `devise_for'
    from /Users/Katy/Desktop/pinteresting/config/routes.rb:2:in `block in <top (required)>'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:341:in `instance_exec'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:341:in `eval_block'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:319:in `draw'
    from /Users/Katy/Desktop/pinteresting/config/routes.rb:1:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `block in load'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:40:in `each'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:40:in `load_paths'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:16:in `reload!'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:26:in `block in updater'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/activesupport-4.0.2/lib/active_support/file_update_checker.rb:75:in `call'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/activesupport-4.0.2/lib/active_support/file_update_checker.rb:75:in `execute'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:27:in `updater'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:6:in `execute_if_updated'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/railties-4.0.2/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `instance_exec'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `run'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/railties-4.0.2/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
    from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
    from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
    from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
    from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/tsort.rb:180:in `each'
    from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
    from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/railties-4.0.2/lib/rails/initializable.rb:54:in `run_initializers'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/railties-4.0.2/lib/rails/application.rb:215:in `initialize!'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/railties-4.0.2/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/Katy/Desktop/pinteresting/config/environment.rb:5:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `block in require'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/railties-4.0.2/lib/rails/application.rb:189:in `require_environment!'
    from /usr/local/rvm/gems/ruby-2.0.0-p353@global/gems/railties-4.0.2/lib/rails/commands.rb:44:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

Any thoughts?

Stefano Sanfilippo
  • 32,265
  • 7
  • 79
  • 80
  • Why not read the error message? It is literally telling your what to do. Add `config.secret_key = '964705f2d08f9196c511948baa14a1ef2ba7693b6eb326f9b177a1377d2c8487aab5736798e4bae6286eb0e36298eac3bceff31be5c357d356db8a22edd04a4d'` to your devise.rb file. – Ashitaka Jan 22 '14 at 00:45
  • Also, googling for the error message would returned http://stackoverflow.com/questions/18080910/devise-secret-key and http://stackoverflow.com/questions/20873524/trouble-installing-devise-gem – Ashitaka Jan 22 '14 at 00:48

2 Answers2

0

This error is happens because of the new devise version, you probably are upgranding the gem version. Add this line into your config/initializers/devise.rb file

config.secret_key = '964705f2d08f9196c511948baa14a1ef2ba7693b6eb326f9b177a1377d2c8487aab5736798e4bae6286eb0e36298eac3bceff31be5c357d356db8a22edd04a4d'

Type: Generate another secrect_key insted of this old one

on your ruby console you can do this:

rake secret

Then copy the hash into your initializer

Kudos for @Ashitaka

Gil Gomes
  • 86
  • 1
  • 5
0

open gem file and add this line gem 'devise'

.........open terminal and type bundle install

now again type in terminal rails generate devise:install

Pranav Singh
  • 17,079
  • 30
  • 77
  • 104