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
“/category/:category_id” part?
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 “/
category/:category_id” part?
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
multiple routes:
map.connect ‘/items/category/:category_id/order/:order/
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.
//jarkko
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.