从Rails 3.1升级到Rails 3.2时出现错误



按照http://guides.rubyonrails.org/3_2_release_notes.html

中提到的步骤进行升级。

现在我正在使用Ruby 1.8.7和Rails 3.1。X(使用系统ruby)。我用ruby 1.8.7安装RVM,并添加到rails 3.2,然后我得到以下错误:

[app]$ rails console
Faraday: you may want to install system_timer for reliable timeouts
$HOME/src/qbol/tapp/config/environment.rb:16:in `add': undefined method `>' for nil:NilClass (NoMethodError)
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/tagged_logging.rb:55:in `add'
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/tagged_logging.rb:61:in `info'
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-3.2.17/lib/active_record/railtie.rb:86
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/lazy_load_hooks.rb:26:in `on_load'
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/lazy_load_hooks.rb:25:in `each'
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/lazy_load_hooks.rb:25:in `on_load'
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-3.2.17/lib/active_record/railtie.rb:80
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/railties-3.2.17/lib/rails/initializable.rb:30:in `instance_exec'
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/railties-3.2.17/lib/rails/initializable.rb:30:in `run'
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/railties-3.2.17/lib/rails/initializable.rb:55:in `run_initializers'
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/railties-3.2.17/lib/rails/initializable.rb:54:in `each'
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/railties-3.2.17/lib/rails/initializable.rb:54:in `run_initializers'
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/railties-3.2.17/lib/rails/application.rb:136:in `initialize!'
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/railties-3.2.17/lib/rails/railtie/configurable.rb:30:in `send'
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/railties-3.2.17/lib/rails/railtie/configurable.rb:30:in `method_missing'
        from $HOME/src/app/config/environment.rb:48
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `require'
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `require'
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:236:in `load_dependency'
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `require'
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/railties-3.2.17/lib/rails/application.rb:103:in `require_environment!'
        from $HOME/.rvm/gems/ruby-1.8.7-p374/gems/railties-3.2.17/lib/rails/commands.rb:40
        from script/rails:6:in `require'
        from script/rails:6

这是我的开发盒。知道为什么会这样吗?

编辑:下面是environment.rb。错误发生在最后一行App::Application.initialize!

# Load the rails application
require File.expand_path('../application', __FILE__)
module ActiveSupport
  class BufferedLogger
    def self.current_user
      Thread.current[:user]
    end
    def self.current_user=(user)
      Thread.current[:user] = user
    end
    def add(severity, message = nil, progname = nil, &block)
      return if @level > severity
      message = (message || (block && block.call) || progname).to_s
      level = {
        0 => "DEBUG",
        1 => "INFO ",
        2 => "WARN ",
        3 => "ERROR",
        4 => "FATAL"
      }[severity] || "UNKNOWN"
      user=BufferedLogger.current_user
      if(!user.nil?)
        idstr = "uid:#{user.id}"
        if !user.current_app_user.nil?
          idstr.concat(", acid: #{user.current_app_user.account_id}")
        end
      else
        idstr=""
      end
      message = "[%s: %s #{idstr}] %s" %
        ["#{level} pid: #{$$}", Time.now.strftime("%y-%m-%d %H:%M:%S"), message]
      message = "#{message}n" unless message[-1] == ?n
      buffer << message
      auto_flush
      message
    end
  end
end
# Initialize the rails application
App::Application.initialize!

错误发生在ActiveSupport::BufferedLogger#add方法调用中,您似乎正在修补该类。在您使用的Rails版本之间,ActiveSupport::BufferedLogger的内部可能会发生变化。

尝试从您的环境中删除所有的ActiveSupport::BufferedLogger代码。Rb来解决这个错误,让你的应用程序运行。然后,如果您仍然需要monkeypatch(不知道为什么),则必须在类的新版本之上重写它。

相关内容

  • 没有找到相关文章