Ruby on rails RubyonRails可选路由段
我试图在Rails应用程序中创建两条带有可选参数的路由 这是我的路由文件:Ruby on rails RubyonRails可选路由段,ruby-on-rails,ruby,Ruby On Rails,Ruby,我试图在Rails应用程序中创建两条带有可选参数的路由 这是我的路由文件: get '(a)(/:area_id/)l/:location_id/(*url_title)', to: 'locations#show', as: :location get 'a/:area_id/(*url_title)', to: 'areas#show', as: :area 导航到以下URL可将我正确路由到正确的控制器: http://localhost:3000/a/1/l/2/seo-friendly
get '(a)(/:area_id/)l/:location_id/(*url_title)', to: 'locations#show', as: :location
get 'a/:area_id/(*url_title)', to: 'areas#show', as: :area
导航到以下URL可将我正确路由到正确的控制器:
http://localhost:3000/a/1/l/2/seo-friendly-title.html
http://localhost:3000/a/1/seo-friendly-title.html
但是,导航到此url不起作用:
http://localhost:3000/l/2/seo-friendly-title.html
我收到一个没有路由匹配的错误。当存在l/:location\u id
部分时,是否可以使a/:area\u id
部分可选
使用Rails 4.2.4
您只需添加另一条路线
get 'l/:location_id/(*url_title)', to: 'locations#show'
没有理由两条路线不能映射到同一个动作