本文介绍了“之前没有这样的中间件可以插入:Rack::Lock (RuntimeError)"升级到 Rails 4 后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到 Rails 4 后出现以下错误:

I'm getting the following error after upgrading to Rails 4:

.../ruby-1.9.3-p125/gems/actionpack-4.0.0.rc2/lib/action_dispatch/middleware/stack.rb:125:in 'assert_index': 没有要插入的中间件之前:Rack::Lock (RuntimeError)

违规行是我的删除斜杠"机架重写规则:

The offending line is my "remove slashes" rack-rewrite rule:

config.middleware.insert_before(Rack::Lock, Rack::Rewrite) do
  r301 %r{^/(.*)/$}, '/$1', :headers => {'Cache-Control' => 'public, max-age='+2.week.to_s}
end

有什么想法吗?

推荐答案

正如错误所暗示的那样(No such middleware to insert before"),问题在于您尝试插入的中间件before(而不是您尝试插入的中间件,这是我最初的假设).

As the error suggests ("No such middleware to insert before"), the issue is with the middleware you are trying to insert before (and not the middleware you are trying to insert, which was my initial assumption).

在 Rails4 中,线程是默认启用的,它删除了 Rack::Lock.

In Rails4, threading is enabled by default which removes Rack::Lock.

要查找替代品,您可以从 rails 项目目录运行 rake 中间件,并在堆栈开头附近寻找一些东西.我将选择 Rack::Runtime,因为它在堆栈的早期,而且看起来很标准.

To find a replacement, you can run rake middleware from your rails project directory, and look for something near the start of the stack. I'm going to pick Rack::Runtime as it is early in the stack, and seems pretty standard.

所以重写配置现在是:

config.middleware.insert_before(Rack::Runtime, Rack::Rewrite) do
  r301 %r{^/(.*)/$}, '/$1', :headers => {'Cache-Control' => 'public, max-age='+2.week.to_s}
end

这篇关于“之前没有这样的中间件可以插入:Rack::Lock (RuntimeError)"升级到 Rails 4 后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 22:06