Code Woes: “undefined local variable or method `version_requirements’”

Frustration (was: threesixtyfive | day 244)

Deciding to install rvm on my development laptop (because I need Ruby 1.9 to work with the latest release of SproutCore), I suddenly find myself receiving the dreaded “version_requirements” error when running a 2.3.x rails application. In all of its glory :

undefined local variable or method `version_requirements' for #
/Users/imarichardson/.rvm/gems/ruby-1.9.2-p180/gems/rails-2.3.5/lib/rails/gem_dependency.rb:119:in `requirement'
/Users/imarichardson/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:269:in `search'
/Users/imarichardson/.rvm/gems/ruby-1.9.2-p180/gems/rails-2.3.5/lib/rails/vendor_gem_source_index.rb:119:in `search'
/Users/imarichardson/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems.rb:247:in `activate'
/Users/imarichardson/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems.rb:1276:in `gem'
/Users/imarichardson/.rvm/gems/ruby-1.9.2-p180/gems/rails-2.3.5/lib/rails/gem_dependency.rb:73:in `add_load_paths'
/Users/imarichardson/.rvm/gems/ruby-1.9.2-p180/gems/rails-2.3.5/lib/initializer.rb:301:in `block in add_gem_load_paths'
/Users/imarichardson/.rvm/gems/ruby-1.9.2-p180/gems/rails-2.3.5/lib/initializer.rb:301:in `each'
/Users/imarichardson/.rvm/gems/ruby-1.9.2-p180/gems/rails-2.3.5/lib/initializer.rb:301:in `add_gem_load_paths'
/Users/imarichardson/.rvm/gems/ruby-1.9.2-p180/gems/rails-2.3.5/lib/initializer.rb:132:in `process'
/Users/imarichardson/.rvm/gems/ruby-1.9.2-p180/gems/rails-2.3.5/lib/initializer.rb:113:in `run'

So through the power of Google I come upon this post from Chris Oliver, and just as I’m about to rollback my version of Ruby to a previous one, I check the source and see an even better solution in this discussion thread. Instead of rolling back ruby gems and making everyone suffer, you can add a non-intrusive update to your environment.rb file. Add this block in right before the initialization and all will be well:

if Gem::VERSION >= "1.3.6"
    module Rails
        class GemDependency
            def requirement
                r = super
                (r == Gem::Requirement.default) ? nil : r
            end
        end
    end
end

No related posts.

  • Kewin2010

    The solution is fairly simple. Just run the following commands to go back to the previous version of rubygems and you should be fine:

    $ gem install rubygems-update -v=’1.4.2′
    $ gem uninstall rubygems-update -v=’1.5.0′
    $ update_rubygems
    That simple revert seems to fix any issue I have with running Rails 2.3 applications. If anyone knows more about the issue and how we can fix it to use rubygems 1.5.x with Rails 2.3 that would be great!

  • Jamjrs

    Try to do as you said upon Kewin2010 but doesnt work … I will try Richardson solution…

  • http://twitter.com/olistik Maurizio De Magnis

    Thanks for the solution, it helped me start an old 2.3.2 rails application avoiding even deprecation warnings :-)

    Unfortunately I’ve messed up the rbenv environment and I had to erase everything:

    $ rm -rf ~/.rbenv/ree-1.8.7-2011.03
    $ rbenv install ree-1.8.7-2011.03
    $ gem install bundler
    $ rbenv rehash
    $ bundle install
    $ bundle exec ./script/server