为什么我会在Middleware/Rack中获得Rails 4.0.2哈希#diff中的Deprecation警告?

 mobiledu2502880383 发布于 2023-02-06 20:08

我正在将Rails 3.2应用程序升级到Rails 4,并且遇到了一些机架中间件的问题:

我收到以下错误: DEPRECATION WARNING: Hash#diff is no longer used inside of Rails, and is being deprecated with no replacement. If you're using it to compare hashes for the purpose of testing, please use MiniTest's assert_equal instead.

似乎触发它的行@app.call(env)来自以下:

 class NoWww

  def initialize(app)
    @app = app
  end

  def call(env)

    request = Rack::Request.new(env)

    if request.host =~ /^[^.]+\.[^.]+$/
      [301, {"Location" => request.url.sub("//","//www.")}, self]
    else
      @app.call(env)
    end

  end


  def each(&block)
  end

end

请注意确定如何@app.call(env)触发此Hash#Diff Deprecation警告......?


UPDATE

我的中间件堆栈如下:

use Rack::Sendfile
use ActionDispatch::Static
use Rack::Rewrite
use Rack::Lock
use #
use Rack::Runtime
use Rack::MethodOverride
use ActionDispatch::RequestId
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use ActionDispatch::DebugExceptions
use BetterErrors::Middleware
use ActionDispatch::RemoteIp
use ActionDispatch::Reloader
use ActionDispatch::Callbacks
use ActiveRecord::ConnectionAdapters::ConnectionManagement
use ActiveRecord::QueryCache
use ActionDispatch::Cookies
use ActionDispatch::Session::CookieStore
use ActionDispatch::Flash
use ActionDispatch::ParamsParser
use Rack::Head
use Rack::ConditionalGet
use Rack::ETag
use NoWww
use OmniAuth::Builder
run JobBoard::Application.routes

bbozo.. 6

猴子补丁Hash#diff这样添加

puts caller.join("\n")

在方法的开头,这将让您知道究竟是什么调用该方法并触发弃用警告(http://www.ruby-doc.org/core-2.1.0/Kernel.html#method-i-caller).然后,如果问题在您的代码中,请修复它(通过使用不同的方法或Hash#diff通过@PaulFioravanti建议添加初始化程序),如果问题不在您的代码中,请将github上的错误报告提交给相应的项目.

如果你在某些方面陷入困境,请告诉我有关你如何陷入困境的细节,我会扩展这个答案

1 个回答
  • 猴子补丁Hash#diff这样添加

    puts caller.join("\n")
    

    在方法的开头,这将让您知道究竟是什么调用该方法并触发弃用警告(http://www.ruby-doc.org/core-2.1.0/Kernel.html#method-i-caller).然后,如果问题在您的代码中,请修复它(通过使用不同的方法或Hash#diff通过@PaulFioravanti建议添加初始化程序),如果问题不在您的代码中,请将github上的错误报告提交给相应的项目.

    如果你在某些方面陷入困境,请告诉我有关你如何陷入困境的细节,我会扩展这个答案

    2023-02-06 20:13 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有