如何修复“未初始化的常量用户”

时间:2016-06-13 19:42:35

标签: ruby-on-rails ruby devise

我试图制作一个新的Devise模型“User”,但我不能。我的服务器也不会加载。我一直收到错误:“未初始化的常量用户”。

这是我试过的:

  • bundle installbundle updategem pristine --all
  • require 'devise'添加到我的application.rb
  • 重启我的服务器,现在无法启动
  • 在我的终端中运行rails g devise:install

这是我的宝石文件:

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

堆栈追踪:

 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'

我不确定发生了什么。

1 个答案:

答案 0 :(得分:3)

您是否制作了模型?

rails generate devise User