14

In my application I have used ruby 1.9.2 and rails 3.0.3 and have also installed Devise gem.The problem begins when I run the Webrick server I get uninitialized constant Devise name Error.

       /home/app/Workspace/project/Library_Management/Library_Management/config/initializers/devise.rb:3:in `<top (required)>': uninitialized constant Devise (NameError)
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/engine.rb:201:in `block (2 levels) in <class:Engine>'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/engine.rb:200:in `each'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/engine.rb:200:in `block in <class:Engine>'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/initializable.rb:25:in `instance_exec'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/initializable.rb:25:in `run'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/initializable.rb:50:in `block in run_initializers'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/initializable.rb:49:in `each'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/initializable.rb:49:in `run_initializers'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/application.rb:134:in `initialize!'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/application.rb:77:in `method_missing'
from /home/app/Workspace/project/Library_Management/Library_Management/config/environment.rb:5:in `<top (required)>'
from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:54:in `require'
from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:54:in `require'
from /home/app/Workspace/project/Library_Management/Library_Management/config.ru:3:in `block in <main>'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/builder.rb:46:in `instance_eval'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/builder.rb:46:in `initialize'
from /home/app/Workspace/project/Library_Management/Library_Management/config.ru:1:in `new'
from /home/app/Workspace/project/Library_Management/Library_Management/config.ru:1:in `<main>'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/builder.rb:35:in `eval'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/builder.rb:35:in `parse_file'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/server.rb:162:in `app'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/server.rb:253:in `wrapped_app'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/server.rb:204:in `start'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands/server.rb:65:in `start'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.rb:30:in `block in <top (required)>'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.rb:27:in `tap'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.rb:27:in `<top (required)>'
from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:58:in `require'
from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:58:in `rescue in require'
from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'

Thanks

3
  • is Devise in your Gemfile.lock? Jul 1, 2011 at 20:05
  • I got the type of error, and for me it actually helped to close the terminal and open a new one. Might be helpfull, but I'm not going to post this as an answer because I do not know what caused this.
    – Automatico
    Dec 26, 2012 at 16:50
  • 1
    Make sure to restart your server after you install a new gem. Feb 3, 2016 at 15:59

10 Answers 10

19

Check your config/application.rb, you need to add require 'devise' and you should be fine.

0
18

In case you are writing an engine which has its own devise config, just add

require 'devise'

on the beginning of devise initializer. In my case I had no devise requirement within application :)

Cheers

5

Make sure you've listed Devise in your Gemfile and run bundle install.

4
  • yes i have listed devise n also ran bundle install but still i am getting the same error..
    – Addicted
    Jul 1, 2011 at 19:40
  • 1
    Inside the Configuration/application.rb i added the line require 'devise' and was able to fix the problem
    – Addicted
    Jul 5, 2011 at 14:39
  • Also, try "bundle update" as it will be a bit more aggressive in installing updates. It updates all gems with all dependencies which often can help ironing out bugs like this. HAve a look at ryanbigg.com/2011/01/why-you-should-run-bundle-update
    – Automatico
    Dec 26, 2012 at 16:53
  • I am still having this same problem- strangely however only in my development environment. I just need to restart my development server and that clears it. But after one user login attempt it blows up again. I tried the includes as listed above but they seem like they should not be needed -and they don't help for me.
    – Eskim0
    Oct 14, 2013 at 21:36
3

I got an error like that when I had a custom devise controller to override the 'new' method to do some custom stuff, and forgot to use 'super'

Do you have a custom controller?

3

I had a similar issue and i found this https://github.com/plataformatec/devise

It says you have to do

rails generate devise:install

Following "Getting Started" on that page got me going

1

if you are not using devise gem anymore then remove

gem 'devise'

from gemfile and delete

config/initializers/devise.rb 

also make sure devise is not being used anywhere

1

I just had that issue, it was because I generated a view model by mistake and I didnt delete it from my routes.rb

1

I had to add require 'devise' in the spec/spec_helper.rb file and that error went away.

0

I added few columns after I install Devise and I added some validations in my user model. From error message, it looks like rails cannot find the essential library therefore it can't find Devise. Maybe checkout the Github devise Wiki page and makes sure all the dependencies are satisfied?

Hope it helps!

0

In your config/application.rb add require 'yaml'. It works for me. Try

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.