升级到Rails 3.1之后,尝试运行Rails服务器后出现以下错误:

/usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0/lib/active_support/whiny_nil.rb:48:in `method_missing': undefined method `context_class' for nil:NilClass (NoMethodError)


也有很多其他的失败,但是我不想全部粘贴。这是我的gemfile:

source 'http://rubygems.org'

gem 'rails', '3.1.0'
gem 'activeadmin'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3', '1.3.4'
gem 'gravatar_image_tag', '0.1.0'
gem 'will_paginate', '3.0.pre2'
gem 'meta_search'
gem 'sass-rails'

group :development do
    gem 'rspec-rails', '2.0.1'
    gem 'annotate-models', '1.0.4'
    gem 'ruby-debug19', :require => 'ruby-debug'
end

group :test do
    gem 'rspec', '2.0.1'
    gem 'webrat', '0.7.1'
    gem 'autotest-fsevent', '0.2.4'
    gem 'autotest-growl', '0.2.9'
    gem 'autotest', '4.3.2'
    gem 'autotest-rails-pure', '4.1.0'
    gem 'spork', '0.8.4'
    gem 'factory_girl_rails', '1.0'
end


这是其余的错误:

from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:68:in `establish_connection'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:60:in `establish_connection'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/railtie.rb:69:in `block (2 levels) in <class:Railtie>'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0/lib/active_support/lazy_load_hooks.rb:26:in `on_load'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/railtie.rb:67:in `block in <class:Railtie>'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0/lib/rails/initializable.rb:25:in `instance_exec'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0/lib/rails/initializable.rb:25:in `run'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0/lib/rails/initializable.rb:50:in `block in run_initializers'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0/lib/rails/initializable.rb:49:in `each'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0/lib/rails/initializable.rb:49:in `run_initializers'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0/lib/rails/application.rb:92:in `initialize!'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/beatjunkie84/Desktop/ProjectX/config/environment.rb:5:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `block in require'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `block in load_dependency'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:640:in `new_constants_in'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
    from /Users/beatjunkie84/Desktop/ProjectX/config.ru:4:in `block in <main>'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.3.4/lib/rack/builder.rb:51:in `instance_eval'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.3.4/lib/rack/builder.rb:51:in `initialize'
    from /Users/beatjunkie84/Desktop/ProjectX/config.ru:1:in `new'
    from /Users/beatjunkie84/Desktop/ProjectX/config.ru:1:in `<main>'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.3.4/lib/rack/builder.rb:40:in `eval'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.3.4/lib/rack/builder.rb:40:in `parse_file'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.3.4/lib/rack/server.rb:200:in `app'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0/lib/rails/commands/server.rb:46:in `app'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.3.4/lib/rack/server.rb:301:in `wrapped_app'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.3.4/lib/rack/server.rb:252:in `start'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0/lib/rails/commands/server.rb:70:in `start'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0/lib/rails/commands.rb:54:in `block in <top (required)>'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0/lib/rails/commands.rb:49:in `tap'
    from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0/lib/rails/commands.rb:49:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'


我能做什么 ?

最佳答案

尝试运行rake rails:update。询问时将其覆盖,然后查看更改并确保保留要保留的文件(因此最后,您将保留它们和您的更改的合并结果)。

这就是我所做的,它修复了与您类似的错误。

关于ruby-on-rails - 升级到Rails 3.1破坏了Rails服务器,出现了奇怪的错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7830750/

10-16 23:19