ruby 通过排除路径文件中定义的路由来检查是否在列出的路由中定义了传入的URL的约束。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 通过排除路径文件中定义的路由来检查是否在列出的路由中定义了传入的URL的约束。相关的知识,希望对你有一定的参考价值。

class OldRoutesConstraint
  def self.matches?(request)
    # TO-DO: add a check to make sure this code block runs only if no other url matches.
    path = {}
    begin
      _routes = Bangthetable::Application.routes
      _routes.disable_clear_and_finalize = true
      _routes.clear!
      _routes.draw do
        # here you can add any route you want
        # and there will only be routes that are listed below in routes.
        get "/documents/show/:id", :to => "sessions#new"
      end
      ActiveSupport.on_load(:action_controller) { _routes.finalize! }
      path = (Rails.application.routes.recognize_path(request.env["PATH_INFO"], :method => request.env["REQUEST_METHOD"].to_sym) rescue {}) || {}
    ensure
      _routes.disable_clear_and_finalize = false
      Bangthetable::Application.routes_reloader.paths.each{ |path| load(path) }
      # this is where we are reloading the original v2 routes.
      # do not remove this piece of code. Coz from next requests, app will fail.
    end
    Bangthetable::Application.routes_reloader.paths.each{ |path| load(path) }

    return path.has_key?(:controller)
  end
end

以上是关于ruby 通过排除路径文件中定义的路由来检查是否在列出的路由中定义了传入的URL的约束。的主要内容,如果未能解决你的问题,请参考以下文章