Ruby on rails 为什么我的路线在它下面被忽略了?
我的routes.rb中有指定以下路线的代码:Ruby on rails 为什么我的路线在它下面被忽略了?,ruby-on-rails,ruby-on-rails-5,Ruby On Rails,Ruby On Rails 5,我的routes.rb中有指定以下路线的代码: concern :searchable do get "search(/:query)", controller: "search", action: :show, as: "search" end scope module: 'custom_domains', as: "custom_domain" do root to: "pages#show", id: "index" concerns :searchable ge
concern :searchable do
get "search(/:query)", controller: "search", action: :show, as: "search"
end
scope module: 'custom_domains', as: "custom_domain" do
root to: "pages#show", id: "index"
concerns :searchable
get '/:id' => "pages#show", as: "page"
match "*path" => "redirects#show", via: [ :get ], as: "redirect"
end
/
/search(/:query)(.:format)
/:id(.:format)
/*path(.:format)
当我尝试访问
/search
时,将跳过该路由,并捕获所有*路径
与该路由匹配。我被难住了。路由是自上而下定义的,并按顺序匹配,因此我认为/search
将是正确的匹配。你知道为什么不是这样吗?我通过将*path
更改为(*path)
找到了解决办法。不过,我不完全明白为什么会这样。我认为这与模式匹配者的贪婪程度有关。如果有人知道原因,我很想听!通过将*路径
更改为(*路径)
,我找到了一个解决方法。不过,我不完全明白为什么会这样。我认为这与模式匹配者的贪婪程度有关。如果有人知道原因,我很想听!