Search code examples
ruby-on-rails-3ruby-on-rails-plugins

After Rails 3 upgrade getting undefined method `root' for nil:NilClass when installing plugins


I'm using the rails_upgrade plugin to move my app from Rails 2.3.14 to Rails 3.0.11. I've backed up and run rails new . in my app directory and gotten the server to boot. All seems ok for me to proceed, but when I try to install a new plugin I get an error:

undefined method `root' for nil:NilClass

Here's the stack trace.

    1.9.2 v@Feather ⚡ rails plugin install https://github.com/rails/rails_upgrade.git
    /Users/vince/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.11/lib/active_support/whiny_nil.rb:48:in `method_missing': undefined method `root' for nil:NilClass (NoMethodError)
from /Users/vince/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.11/lib/rails/commands/plugin.rb:282:in `initialize'
from /Users/vince/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.11/lib/rails/commands/plugin.rb:352:in `new'
from /Users/vince/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.11/lib/rails/commands/plugin.rb:352:in `parse!'
from /Users/vince/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.11/lib/rails/commands/plugin.rb:547:in `<top (required)>'
from /Users/vince/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.11/lib/active_support/dependencies.rb:239:in `require'
from /Users/vince/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.11/lib/active_support/dependencies.rb:239:in `block in require'
from /Users/vince/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.11/lib/active_support/dependencies.rb:225:in `block in load_dependency'
from /Users/vince/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.11/lib/active_support/dependencies.rb:593:in `new_constants_in'
from /Users/vince/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.11/lib/active_support/dependencies.rb:225:in `load_dependency'
from /Users/vince/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.11/lib/active_support/dependencies.rb:239:in `require'
from /Users/vince/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.11/lib/rails/commands.rb:17:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

Looks like the culprit is this line: @rails_root = RailsEnvironment.default.root


Solution

  • Weird, finally figured it out. Turns out it was the slim_scrooge gem in my Gemfile that was causing the issue. Removed it from my bundle and all is good again. Obscure problem, but hopefully one that saves somebody else time later on.