2

I tried to make a new Devise model "User", but I can't. My server won't load either. I keep getting the error: "uninitialized constant User".

Here's what I tried:

  • bundle install, bundle update, and gem pristine --all
  • Adding require 'devise' into my application.rb
  • Restarting my server, which now won't launch
  • Running rails g devise:install in my terminal

Here's my gem file:

source 'https://rubygems.org'

gem 'rails', '4.2.6'
gem 'pg', '~> 0.15'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'

gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'bootstrap-sass', '~> 3.3.6'
gem 'rails_12factor'
gem "figaro"
gem 'devise'
gem 'paperclip', github: 'thoughtbot/paperclip' 

group :development, :test do
  gem 'byebug'
  gem 'sqlite3'
end

group :development do
  gem 'web-console', '~> 2.0'
  gem 'spring'
end

Stack trace:

 WARNING: Nokogiri was built against LibXML version 2.9.4, but has dynamically loaded 2.9.2
/Users/Sam/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.6/lib/active_support/inflector/methods.rb:261:in `const_get': uninitialized constant User (NameError)
    from /Users/Sam/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.6/lib/active_support/inflector/methods.rb:261:in `block in constantize'
    from /Users/Sam/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.6/lib/active_support/inflector/methods.rb:259:in `each'
    from /Users/Sam/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.6/lib/active_support/inflector/methods.rb:259:in `inject'
    from /Users/Sam/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.6/lib/active_support/inflector/methods.rb:259:in `constantize'
    from /Users/Sam/.rvm/gems/ruby-2.2.1/gems/devise-4.1.1/lib/devise.rb:289:in `get'
    from /Users/Sam/.rvm/gems/ruby-2.2.1/gems/devise-4.1.1/lib/devise/mapping.rb:81:in `to'
    from /Users/Sam/.rvm/gems/ruby-2.2.1/gems/devise-4.1.1/lib/devise/mapping.rb:76:in `modules'
    from /Users/Sam/.rvm/gems/ruby-2.2.1/gems/devise-4.1.1/lib/devise/mapping.rb:93:in `routes'
    from /Users/Sam/.rvm/gems/ruby-2.2.1/gems/devise-4.1.1/lib/devise/mapping.rb:160:in `default_used_route'

I'm not sure what is happening.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Sam Henrichs
  • 67
  • 1
  • 9
  • Please share the top few lines of the stacktrace. – Raffael Jun 13 '16 at 19:46
  • How are you trying to "make a new devise model User"? What happens when you do that? – Raffael Jun 13 '16 at 20:08
  • I run `rails g devise user` I get the above error – Sam Henrichs Jun 13 '16 at 20:10
  • Possible duplicate of [Mac user and getting WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 2.7.3](http://stackoverflow.com/questions/6802410/mac-user-and-getting-warning-nokogiri-was-built-against-libxml-version-2-7-8-b) – ruby_newbie Jun 13 '16 at 20:12
  • @ruby_newbie Good hint. The warning is not part of the question, though, so please don't mark as duplicate. – Raffael Jun 13 '16 at 20:19
  • 2
    I see, so you are getting the error while trying to run `rails g devise User`. Maybe you were a bit too eager with setting devise up? Please try removing all devise related code from your application. Especially the from your `application.rb`. Only keep the entry in the Gemfile. Then try again to run the generator. Does that work? – Raffael Jun 13 '16 at 20:22
  • There is no need (not in this case, very rarely with other gems) to manually `require 'devise'` anywhere in your code. Rails will take care of this. The error means you havent generated the model. When you generate the model you have to run the migrations. Please red the gem's getting started documentaiton and output of the commands you run. You are missing steps detailed in there. – Leonel Galán Jun 13 '16 at 20:39
  • @Raffael yup that worked. Thank you very much – Sam Henrichs Jun 14 '16 at 00:16
  • 1
    Glad it helped. Leito also gave good advise in suggesting that you follow the gem's getting started instructions closely. – Raffael Jun 15 '16 at 08:20

1 Answers1

3

Have you generated your model?

rails generate devise User
Ursus
  • 29,643
  • 3
  • 33
  • 50