Rails 5.0 将字符串或符号传递给中间件构建器弃用警告
Rails 5.0 Passing strings or symbols to the middleware builder Deprecation Warning
rails 5.0
、ruby 2.6.4
我正在将应用程序升级到 rails 5.0
。我目前正在尝试解决一些弃用警告。这是一个我找不到任何帮助的问题,我不确定还能去哪里找。
DEPRECATION WARNING: Passing strings or symbols to the middleware builder is deprecated, please change
them to actual class references. For example:
"CatchRequestErrors" => CatchRequestErrors
我只在两个文件中找到“CatchRequestErrors”:
app/middleware/catch_request_errors.rb
class CatchRequestErrors
def initialize(app)
@app = app
end
def call(env)
begin
@app.call(env)
rescue ActionController::BadRequest => error
::Rails.logger.warn("WARN: 400 ActionController::BadRequest: #{env['REQUEST_URI']}")
@html_400_page ||= File.read(::Rails.root.join('public', '400.html'))
[
400, { "Content-Type" => "text/html" },
[ @html_400_page ]
]
end
end
end
和
config/application.rb
# Middleware that catches the ActionController::BadRequest error, logs it and returns a 400 error page
config.middleware.insert_before Rack::Head, "CatchRequestErrors"
我进行了一些谷歌搜索,但没有发现任何关于如何解决此问题的突出问题。
config/application.rb
中的行是否有特定的语法?
改变
config.middleware.insert_before Rack::Head, "CatchRequestErrors"
到
config.middleware.insert_before Rack::Head, CatchRequestErrors
假设它已正确加载,您应该没问题。
rails 5.0
、ruby 2.6.4
我正在将应用程序升级到 rails 5.0
。我目前正在尝试解决一些弃用警告。这是一个我找不到任何帮助的问题,我不确定还能去哪里找。
DEPRECATION WARNING: Passing strings or symbols to the middleware builder is deprecated, please change
them to actual class references. For example:
"CatchRequestErrors" => CatchRequestErrors
我只在两个文件中找到“CatchRequestErrors”:
app/middleware/catch_request_errors.rb
class CatchRequestErrors
def initialize(app)
@app = app
end
def call(env)
begin
@app.call(env)
rescue ActionController::BadRequest => error
::Rails.logger.warn("WARN: 400 ActionController::BadRequest: #{env['REQUEST_URI']}")
@html_400_page ||= File.read(::Rails.root.join('public', '400.html'))
[
400, { "Content-Type" => "text/html" },
[ @html_400_page ]
]
end
end
end
和
config/application.rb
# Middleware that catches the ActionController::BadRequest error, logs it and returns a 400 error page
config.middleware.insert_before Rack::Head, "CatchRequestErrors"
我进行了一些谷歌搜索,但没有发现任何关于如何解决此问题的突出问题。
config/application.rb
中的行是否有特定的语法?
改变
config.middleware.insert_before Rack::Head, "CatchRequestErrors"
到
config.middleware.insert_before Rack::Head, CatchRequestErrors
假设它已正确加载,您应该没问题。