Ruby on rails 基于参数的铁路线路约束

Ruby on rails 基于参数的铁路线路约束,ruby-on-rails,refactoring,rails-routing,Ruby On Rails,Refactoring,Rails Routing,我正在尝试设置一个仅用于开发的路由,该路由与url中包含/attachments/的路由除外的所有路由都匹配。这可能吗 例如: match '*a', to: 'errors#four_oh_four', via: :all, constraints: { all: /^(?!.*attachments).*$/ } if Rails.env.development? 根据我在这里看到的一些帖子,我是如何解决这个问题的: match '*a', to: 'errors#four_oh_

我正在尝试设置一个仅用于开发的路由,该路由与url中包含
/attachments/
的路由除外的所有路由都匹配。这可能吗

例如:

  match '*a', to: 'errors#four_oh_four', via: :all, constraints: { all: /^(?!.*attachments).*$/ } if Rails.env.development?

根据我在这里看到的一些帖子,我是如何解决这个问题的:

  match '*a', to: 'errors#four_oh_four', via: :all, constraints: ->(req) { !req.env['REQUEST_PATH'].include?('attachments') } if Rails.env.development?
通过Rubocops: 指南可在此处找到: