How to make parameters optional when using Rails named routes?

Posted by Jason on Stack Overflow See other posts from Stack Overflow or by Jason
Published on 2010-05-04T16:43:45Z Indexed on 2010/05/04 16:48 UTC
Read the original article Hit count: 434

Filed under:
|
|
|

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!

© Stack Overflow or respective owner

Related posts about rails

Related posts about routing