从Rails 3.1升级到Rails 3.2时出错

时间:2014-03-18 12:32:30

标签: ruby ruby-on-rails-3 ruby-on-rails-3.2 ruby-on-rails-3.1

升级步骤按照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!

1 个答案:

答案 0 :(得分:1)

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

尝试从您的environment.rb中删除所有ActiveSupport::BufferedLogger代码,以解决此错误并让您的应用运行。然后,如果你仍然需要monkeypatch(不知道为什么),你必须在更新版本的类之上重写它。