From a1fdf402c02f4ae8ef0b49c2481298565620efa6 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 16 Aug 2010 01:10:34 +0200 Subject: routing guide: wildcard segments are quite flexible, go beyond the simple use case --- railties/guides/source/routing.textile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index d92c66cfd2..457b6804b1 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -516,6 +516,22 @@ match 'photos/*other' => 'photos#unknown' This route would match +photos/12+ or +/photos/long/path/to/12+, setting +params[:other]+ to +"12"+ or +"long/path/to/12"+. +Wildcard segments do not need to be last in a route. For example + + +match 'books/*section/:title' => 'books#show' + + +would match +books/some/section/last-words-a-memoir+ with +params[:section]+ equals +"some/section"+, and +params[:title]+ equals +"last-words-a-memoir"+. + +Techincally a route can have even more than one wildard segment indeed, the matcher assigns segments to parameters in an intuitive way. For instance + + +match '*a/foo/*b' => 'test#index' + + +would match +zoo/woo/foo/bar/baz+ with +params[:a]+ equals +"zoo/woo"+, and +params[:b]+ equals +"bar/baz"+. + h4. Redirection You can redirect any path to another path using the +redirect+ helper in your router: -- cgit v1.2.3