基于param的rails路由约束

时间:2016-02-22 18:44:49

标签: ruby-on-rails refactoring rails-routing

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

示例:

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

1 个答案:

答案 0 :(得分:0)

基于我在这里遇到的一些帖子,我是如何解决这个问题的:

  match '*a', to: 'errors#four_oh_four', via: :all, constraints: ->(req) { !req.env['REQUEST_PATH'].include?('attachments') } if Rails.env.development?

通过Rubocops:https://github.com/bbatsov/ruby-style-guide 在此处找到指南:https://github.com/rails/rails/issues/7924