Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 为什么我的路线在它下面被忽略了?_Ruby On Rails_Ruby On Rails 5 - Fatal编程技术网

Ruby on rails 为什么我的路线在它下面被忽略了?

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

我的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

   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)
找到了解决办法。不过,我不完全明白为什么会这样。我认为这与模式匹配者的贪婪程度有关。如果有人知道原因,我很想听!通过将
*路径
更改为
(*路径)
,我找到了一个解决方法。不过,我不完全明白为什么会这样。我认为这与模式匹配者的贪婪程度有关。如果有人知道原因,我很想听!