简体   繁体   English

[导轨中的控制台]。 未初始化的常量类

[英][console in rails]. uninitialized constant Class

when i run a method in terminal of rails.当我在 rails 终端运行一个方法时。 first time, it working :第一次,它工作:

 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>

but when i try run code above again但是当我再次尝试运行上面的代码时

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>'

Why?为什么? and how to fix this error??以及如何解决这个错误?

The errors you are getting seem to be intermittent.您遇到的错误似乎是间歇性的。 In your question text, the error is uninitialized constant Spree::Campaign , whereas in your question title, the error is uninitialized constant Class .在您的问题文本中,错误是uninitialized constant Spree::Campaign ,而在您的问题标题中,错误是uninitialized constant Class

This points to there being something fundamentally wrong with your Ruby installation.这表明您的 Ruby 安装存在根本性的错误。 Class is a core Ruby class, and the Class constant should always be there. Class是 Ruby 的核心类,并且Class常量应该始终存在。 It's hard to diagnose with just the information you have given, but it appears that constant lookup is broken in your Ruby installation.仅凭您提供的信息很难进行诊断,但是在您的 Ruby 安装中,持续查找似乎被破坏了。

I recommend re-installing Ruby.我建议重新安装Ruby。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM