使用 Rails 命名路由时如何使参数可选?
我有一个命名路由:
map.find '/find/:category/:state/:search_term/:permalink', :search_term=>nil, :controller=>'find', :action=>'show_match'
并且以下 URL 与其匹配 &工作正常:
http://localhost:3000/find/cars/ca/TestSeachTerm/bumpedupphoto-test
但如果我取出第二个最后一个参数,即“TestSearchTerm”,则路线无法匹配,即使我在路线中有 :search_term=>nil 。
http://localhost:3000/find/cars/ca//bumpedupphoto-test
谁能看到我做错了什么吗?这几天正在尝试解决这个问题。
谢谢!
I have a named route:
map.find '/find/:category/:state/:search_term/:permalink', :search_term=>nil, :controller=>'find', :action=>'show_match'
and the following URL matches it & works OK:
http://localhost:3000/find/cars/ca/TestSeachTerm/bumpedupphoto-test
but if I take out the 2nd last parameter i.e. "TestSearchTerm", then the route fails to get matched, even though I have :search_term=>nil in the route.
http://localhost:3000/find/cars/ca//bumpedupphoto-test
Can anyone see what I am doing wrong? Being trying to solve this for a few days now.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在当前路线之后添加以下内容:
Add this after your current route: