1

我有一个带有单个索引操作的控制器。相同的资源有一些不需要控制器中的任何东西的静态资产。曾经有一些其他的现在已经消失了,但是网络上到处都是挥之不去的链接。

有没有一种方法可以匹配任何/resource/*没有在控制器中定义的操作或命名视图中的请求app/views/resources/____并将其路由到默认值(resource#index在这种情况下会很好)。

4

1 回答 1

2
class MyConstraint
  BYPASSED_ROUTES = ['anything']

  def matches?(request)
    BYPASSED_ROUTES.map {|r| request.path.include?(r)}.empty?
  end
end

MyApp::Application.routes.draw do
  # Insert other routes before the catch-all one
  match "/resource/*path" => "resource#index", :constraints => MyConstraint.new
end
于 2013-01-25T23:50:20.940 回答