Jason
Jason

Reputation: 23395

How to make parameters optional when using Rails named routes?

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!

Upvotes: 1

Views: 1667

Answers (1)

Zepplock
Zepplock

Reputation: 29165

Add this after your current route:

map.find '/find/:category/:state/:permalink', :controller=>'find', :action=>'show_match'

Upvotes: 1

Related Questions