I was in the midst of Ruby on Rails coding, having run several rails generate methods over the last hour, whe开发者_运维百科n suddenly a new generate command threw up an error message. A similar error came when I tried to run my tests via rake. And then on the command line for just "rails". And then the same error for the "gem" command.
So I presume, somehow, I have broken my "rubygems" Gem file ? Which is worrying, as I was coding in Rubymine and, well frankly, nowhere near it !
Can anyone help explain what might have happened, and what the best fix might be ? For now, I'll try reinstalling Ruby, but that's a costly workaround I'd like to avoid doing more than once.
The error stacktrace looks as follows :
C:\Users\Ben>rails
C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:127:in `load_gems_in':
private method `load' called for Gem::Specification:Class (NoMethodError)
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems/deprecate.rb:38:in `skip_during'
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:126:in `load_gems_in'
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:125:in `each'
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:125:in `load_gems_in'
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:122:in `reverse_each'
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:122:in `load_gems_in'
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:321:in `refresh!'
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:97:in `initialize'
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:1051:in `new'
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:1051:in `source_index'
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:243:in `activate_dep'
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:236:in `activate'
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:1307:in `gem'
from C:/dev/lang/Ruby187/bin/rails:18
My Gem file (for the project above) is:
source 'http://rubygems.org'
gem 'rails', '3.0.7'
gem 'sqlite3'
gem "jquery-rails"
Although the error occurs at all command line instances.
[EDIT] at this stage I have fully reinstalled ruby and rails and the problem has gone. I have kept the old installation directory though, in case we can get to the bottom of this issue, or in case it reoccurs !
[SECOND EDIT]New installation, after a machine reboot, gem has once more started failing, and RubyMine is saying it can't find any gems (even rubygems) :
C:\Users\Ben>gem
C:/dev/lang/Ruby187/lib/ruby/1.8/optparse.rb:1433:in `private': undefined method `search' for class `OptionParser' (NameError)
from C:/dev/lang/Ruby187/lib/ruby/1.8/optparse.rb:1433
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems/command.rb:7
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:7
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems/gem_runner.rb:7
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from C:/dev/lang/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from C:/dev/lang/Ruby187/bin/gem:9
Maybe RubyMine is screwing up the install ? Or Windows 7 ? Never has a problem with my core development language getting corrupted - very frustrating !
My hunch was correct - RubyMine was to blame... and the user too, of course !
Far too used to using refactoring tools in Intellij for Java, I refactored some fairly common methods names in my controllers (such as changing "show" to "index") and ended up refactoring into the Ruby 1.8 standard library files too !
Need to double-check what refactoring is doing, going forward, and try to limit it just to my project and not the whole SDK :)
精彩评论