【发布时间】:2015-09-28 21:39:18
【问题描述】:
我正在尝试在我的 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-title.html
http://localhost:3000/a/1/seo-friendly-title.html
但是,导航到此 url 不起作用:
http://localhost:3000/l/2/seo-friendly-title.html
我收到No route matches 错误。当l/:location_id 部分存在时,是否可以将a/:area_id 部分设为可选?
使用Rails 4.2.4。
【问题讨论】:
标签: ruby-on-rails ruby