uninitialized constant Devise (NameError) on new installation

2,775 views
Skip to first unread message

Serenity

unread,
Dec 10, 2010, 11:26:12 PM12/10/10
to Devise
Hello,

I have what I believe is a fairly straightforward rails app, but the
devise model generator crashes, and the app itself crashes on boot. I
ran rails generate devise:install and it worked. But when I run 'rails
generate devise User', I get 'devise.rb:3: uninitialized constant
Devise (NameError)'. I get the same result when I run 'rails server'.

Note that in a brand new rails 3 app it works correctly. The app in
question is a former rails 2 app that I semi-hand converted to rails
3, so it seems likely that I messed something up when I did that.

Trying to anticipate what questions I'm going to be asked here goes:

t-foil% rails generate devise:install
create config/initializers/devise.rb
create config/locales/devise.en.yml
[helpful getting started message omitted]

t-foil% rails generate devise User
/Users/dorfman/dev/rails/score/config/initializers/devise.rb:3:
uninitialized constant Devise (NameError)
from /Users/dorfman/dev/rails/score/mysql2/ruby/1.8/gems/
railties-3.0.3/lib/rails/engine.rb:201
from /Users/dorfman/dev/rails/score/mysql2/ruby/1.8/gems/
railties-3.0.3/lib/rails/engine.rb:200:in `each'
from /Users/dorfman/dev/rails/score/mysql2/ruby/1.8/gems/
railties-3.0.3/lib/rails/engine.rb:200
from /Users/dorfman/dev/rails/score/mysql2/ruby/1.8/gems/
railties-3.0.3/lib/rails/initializable.rb:25:in `instance_exec'
[etc]

For what it's worth, I notice something odd when I run 'bundle
install'. In addition to seeing devise and warden getting installed, I
also see

t-foil% bundle install
Fetching source index for http://rubygems.org/
[...]
Installing warden (1.0.2)
Installing devise (1.1.5)
[...]
Your bundle is complete! Use `bundle show [gemname]` to see where a
bundled gem is installed.

Your bundle was installed to `mysql2`
%t-foil

Notice the comment about mysql2, even though I had already previously
installed mysql2. Also, mysql2 installed in rails root - I don't know
if that's normal or not, seems weird to me.

Here is my Gemfile:

source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'mysql2'
gem 'haml'
gem 'map_by_method'
gem 'prototype_legacy_helper', '0.0.0', :git => 'git://github.com/
rails/prototype_legacy_helper.git'
gem 'devise', '1.1.5'
gem 'ruby-debug'

Serenity

unread,
Dec 10, 2010, 11:36:56 PM12/10/10
to Devise
Well, after some fiddling around, I found that adding "require
'devise'" to the bottom of config/application.rb got it working.

However I would love to know why I didn't have to do that in a brand
new rails 3 app. Any ideas?

Thanks,
Avram

Michael Latta

unread,
Dec 11, 2010, 12:04:33 AM12/11/10
to plataforma...@googlegroups.com, Devise
Did you have devise in your gemfile? Any earlier message was not copied. Did you bundle install? Obvious things to check, but might have been overlooked? I just setup a new project and had no problem.

Michael

Sent from my iPad

Serenity

unread,
Dec 11, 2010, 9:36:42 AM12/11/10
to Devise
Michael,

All of what you suggested is in my original post. It still did not
work after all of that. The "key ingredient" was putting "require
'devise'" in my application.rb, which doesn't make sense, since that
is not required in a brand new project. So yes, I had the same
experience as you, in a brand new project, it "just works."

I am guessing that this is not a devise-specific problem, but the
result of having missed something (or done something wrong) when I
converted this project from rails2 to rails3.

Thanks,
Avram
Reply all
Reply to author
Forward
0 new messages