Retrieve a capture group in routing?


I’m trying to retrieve a capture group from a regular expression for a
given route. Here’s the code:

map.category ‘:category’, :controller => ‘product’, :action =>
‘list’, :requirements => { :category => /[\w|-]+(-\d*)?/}

I’d like to capture the end (-\d*) inside “:page” to match “flowers”
but also “flowers-p2”, “flowers-p3” etc for pages numbers. I’d like to
make it pass the following test:

assert_routing “flowers-p2”, :controller => ‘product’, :action =>
‘list’, :category => ‘flowers’, :page => 2
assert_routing “flowers”, :controller => ‘product’, :action =>
‘list’, :category => ‘flowers’

Does anyone knows if it’s possible to achieve this (and how) ?

Thibaut Barrère / LoGeek - learning content for developers - tools for a better day

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs