On 18.11.2005, at 11.07, CSN wrote:
Is it possible to specify a route like this:
and have any of the parts in parentheses be optional? I know I can
make :category_id and the other
vars optional, but is it possible with the entire “/
You can only make variables optional from the tail end. So in
“/:a/:b/:c” either :c, :c and :b or all :c, :b and :a can be
optional. However, just :a or just :b cannot be optional.
Why? Because there’s no way for Rails to know whether your url
meant :a/:b or :a/:c.
However, what you want to accomplish is possible, albeit with
page/:page’, :controller => ‘foo’, :action => ‘bar’
map.connect ‘/items/order/:order/page/:page’, :controller =>
‘foo’, :action => ‘bar’
map.connect ‘/items/page/:page’, :controller => ‘foo’, :action => ‘bar’
and so on and so forth…
Kind of awkward, that’s true. But afaik there’s no way around it if
you want that even parts in the middle of an url are optional.