问题
I need to set up routes wich will match links like this:
1: fixed/9731-monday-tuesday-wednesday-thursday-friday/922-another
2: fixed/potatoe
First case has unlimited parameters, however all of them are in format [number]-[some-string]. Second case has only one parameter with caracters only.
I'v tried this:
map.connect("/fixed/*param_list",
:controller => 'first',
:action => 'index',
:requirements => {:param_list => /(\d+-[\w-]+)/})
map.connect("/fixed/:category",
:controller => 'second',
:action => 'index')
However first route with requirements doesn't work as with wildcard any more. It only match ulr like /fixed/922-another but not two and more dimensional /fixed/922-another/123-and-more.
So my question is: Is possible to parametrized wildcard route via requirments? And how to set up it in my case.
回答1:
It seems like your regexp is wrong. Shouldn't it be /\d+-[\w-]+(\/\d+-[\w-]+)*/
in order to handle multiple parameters?
来源:https://stackoverflow.com/questions/5326679/rails-routes-with-wildcard-and-requirements