Wildcard Routes
With 'wildcard' routes you capture n segments of your url and get them back as parameters. Let's take a look at a couple of examples, to make this easier to understand:
Mack::Routes.build do |r| r.connect '/chapters/*chaps', :controller => :chapters, :action => :show r.authors '/a/*authors/z', :controller => :books, :action => :peeps end
Wildcards are defined in when building routes by using a '*' instead of the normal ':' for capturing embedded parameters. Here are some examples:
Mack::Routes.retrieve('/chapters/1/2/3')
# => {:chaps => ['1', '2', '3'], :format => 'html', :controller => :chapters, :action => :show, :method => :get}
Mack::Routes.retrieve('/chapters/1')
# => {:chaps => ['1'], :format => 'html', :controller => :chapters, :action => :show, :method => :get}
Mack::Routes.retrieve('/a/me/z')
# => {:authors => ['me'], :format => 'html', :controller => :books, :action => :peeps, :method => :get}
Mack::Routes.retrieve('/a/me/you/z')
# => {:authors => ['me', 'you'], :format => 'html', :controller => :books, :action => :peeps, :method => :get}
As you can see in the first example we said everything that comes after '/chapters/' should get sent to the :chaps parameter. Wildcard parameters will also get returned as an Array. So when we have the url '/chapters/1/2/3' we end up with a parameter called :chaps that is an Array containing the values, '1', '2', and '3'.
The reverse of this is also true. We can build wildcard urls as well:
authors_url(:authors => ['me', 'you']) # => '/a/me/you/z'