Rails 6:捕获所有路由约束不起作用

Rails 6: Catch all route constraint not working

我在路线文件的底部放置了一条捕获所有路线。令人恼火的是,Active Storage 请求也指向相同的操作。我不要那个。

我在 Github 上阅读了 on SO and this issue,建议向路由添加约束。

Rails.application.routes.draw do
#...
  get "/*slug" => "profiles#show",
      param: :slug,
      as: "profile",
      contraints: lambda { |req|
        req.path.exclude? "rails/active_storage"
      }
end

但是,这对我不起作用。 ActiveStorage 请求仍在 profiles#show。我的约束有什么问题?我错过了什么明显的东西吗?

你打错了。

应该是constraints:而不是contraints: