[控制台在轨道]。未初始化的常数类

时间:2015-10-29 04:28:48

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4

当我在rails的终端中运行方法时。 第一次,它工作:

 Spree::Campaign.first
 Campaign Load (0.4ms)  SELECT  `campaigns`.* FROM `campaigns`   ORDER BY `campaigns`.`id` ASC LIMIT 1
 => #<Campaign id: 1, name: "campaign 1", user_id: 1, created_at: "2015-10-27 06:48:01", updated_at: "2015-10-29 04:22:03", description: nil, active: true>

但是当我尝试再次运行上面的代码时

Spree::Campaign.first
NameError: uninitialized constant Spree::Campaign
from (irb):2
from /home/kop/.rvm/gems/ruby-2.1.4@rails3213/gems/railties-4.1.6/lib/rails/commands/console.rb:90:in `start'
from /home/kop/.rvm/gems/ruby-2.1.4@rails3213/gems/railties-4.1.6/lib/rails/commands/console.rb:9:in `start'
from /home/kop/.rvm/gems/ruby-2.1.4@rails3213/gems/railties-4.1.6/lib/rails/commands/commands_tasks.rb:69:in `console'
from /home/kop/.rvm/gems/ruby-2.1.4@rails3213/gems/railties-4.1.6/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /home/kop/.rvm/gems/ruby-2.1.4@rails3213/gems/railties-4.1.6/lib/rails/commands.rb:17:in `<top (required)>'
from /home/kop/.rvm/gems/ruby-2.1.4@rails3213/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
from /home/kop/.rvm/gems/ruby-2.1.4@rails3213/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
from /home/kop/rails/donghoxteen/bin/rails:8:in `<top (required)>'
from /home/kop/.rvm/rubies/ruby-2.1.4/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/kop/.rvm/rubies/ruby-2.1.4/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'

为什么呢?以及如何修复此错误??

1 个答案:

答案 0 :(得分:0)

你得到的错误似乎是间歇性的。在您的问题文本中,错误为uninitialized constant Spree::Campaign,而在您的问题标题中,错误为uninitialized constant Class

这表明Ruby安装存在根本性的问题。 Class是一个核心Ruby类,Class常量应始终存在。仅使用您提供的信息进行诊断很困难,但在Ruby安装中似乎会断开常量查找。

我建议重新安装Ruby。