简体   繁体   中英

[console in rails]. uninitialized constant Class

when i run a method in terminal of 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 .

This points to there being something fundamentally wrong with your Ruby installation. Class is a core Ruby class, and the Class constant should always be there. It's hard to diagnose with just the information you have given, but it appears that constant lookup is broken in your Ruby installation.

I recommend re-installing Ruby.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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