我的路线文件里有个奇怪的问题。这是我需要明白的部分,这条路不起作用
# V3
# V3 - Home Page
match '/:locale' => 'v3/home#index', :constraints => V3Constraint, :as => :home
# V3 - Search
match '(/:locale)/products/search' => 'v3/products#search', :constraints => V3Constraint
# V3 - Categories index
match '(/:locale)/categories/(:parent_category((/*path)/:category))/(:full)' => 'v3/products#index', :constraints => V3Constraint, :as => :category
# V3 - Prduct Page
match '/:locale/products/:product' => 'v3/products#show', :constraints => V3Constraint, :as => :product
match '(/:locale)/search_amazon' => 'v3/products#search_amazon', :constraints => V3Constraint
# EOF V3但这份工作
#V3 - Search
match '(/:locale)/products/search' => 'v3/products#search', :constraints => V3Constraint
# V3 - Categories index
match '(/:locale)/categories/(:parent_category((/*path)/:category))/(:full)' => 'v3/products#index', :constraints => V3Constraint, :as => :category
# V3 - Product Page
match '/:locale/products/:product' => 'v3/products#show', :constraints => V3Constraint, :as => :product
match '(/:locale)/search_amazon' => 'v3/products#search_amazon', :constraints => V3Constraint
# V3 - Home Page
match '/:locale' => 'v3/home#index', :constraints => V3Constraint, :as => :home如果我使主页路由比其他路由具有更低的优先级,那么它可以工作,但是如果它与其他路由一样位于顶部: match '(/:locale)/search_amazon‘=> 'v3/products#search_amazon',:=> V3Constraint将导致主页。
有谁能解释一下为什么要发生这种事吗?
谢谢。
发布于 2015-02-09 12:12:42
拥有这样的路由,<yourdomain>/search_amazon将匹配这两条路由中的第一条
match '(/:locale)/search_amazon' => 'v3/products#search_amazon', :constraints => V3Constraint在本例中,它将匹配,因为locale在这里是可选的。
match '/:locale' => 'v3/home#index', :constraints => V3Constraint, :as => :home在这里,它将匹配使search_amazon作为locale的值。
https://stackoverflow.com/questions/28393046
复制相似问题