我正在尝试制作更多语义网址,如下所示: -
//with one params
get 'location/:location' => 'home#show_by_location', as: :show_by_location
//with two params
get ':location/:name/' => 'home#show_details' , as: :show_details
它们几乎相似,但它们没有工作,因为第二个url永远不会被调用,因为rails认为它们是相同的,因此只调用第一个(按预期)。那么我该如何对待两者都不同。
提前致谢。
答案 0 :(得分:1)
交换订单并使用constraint告诉我:location
不能成为字符串'location'
:
get ':location/:name/' => 'home#show_details', constraints: { location: /^(location)/ }, as: :show_details
get 'location/:location' => 'home#show_by_location', as: :show_by_location