NameError:未初始化的常量用户

时间:2016-02-25 01:26:31

标签: ruby-on-rails devise console

我正在使用Rails作曲家的rails-devise应用程序。在我尝试与控制台中的模型进行交互之前,一切似乎都很好。 我尝试了命令:

rails console
User.all

我从控制台收到以下错误:

NameError: uninitialized constant User
from (irb):2
from /Users/msarr/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5.1/lib/rails/commands/console.rb:110:in `start'
from /Users/msarr/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5.1/lib/rails/commands/console.rb:9:in `start'
from /Users/msarr/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/msarr/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/msarr/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5.1/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/msarr/Desktop/deployment/YouServe/bin/rails:9:in `<top (required)>'
from /Users/msarr/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/msarr/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'

这是我的Gemfile:

  source 'https://rubygems.org'
  ruby '2.2.1'
  gem 'rails', '4.2.5.1'
  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 'carrierwave'
  gem 'mini_magick'
  gem 'fog'                  
  gem 'administrate'
  gem 'devise'
  gem 'devise_invitable'
  gem 'foundation-rails', '~> 5.5'
  gem 'high_voltage'
  gem 'simple_form'

 group :development, :test do
  gem 'byebug'
  gem 'sqlite3'
end
group :development do
  gem 'web-console', '~> 2.0'
  gem 'spring'
  gem 'better_errors'
  gem 'hub', :require=>nil
  gem 'quiet_assets'
  gem 'rails_layout'
end

group :production do
 gem 'pg'
 gem 'rails_12factor'
 gem 'unicorn'
end

3 个答案:

答案 0 :(得分:8)

重新启动弹簧加载器。

spring stop

然后运行rails c它工作正常

答案 1 :(得分:0)

请务必在您的Gemfile中加入gem 'devise'并运行bundle

您还需要运行以下

rails generate devise:install
rails generate devise User
rake db:migrate

现在,您应该可以访问User.all

中的rails c

答案 2 :(得分:0)

您项目的架构是什么样的?如果您的模型周围有任何模块或命名空间(例如APIv1),那么您必须使用命名空间调用它们,即V1::User.all