I have two routes in my routes.rb :
map.connect ‘’, :controller => “main”, :action => “index”
map.connect ‘admin/:action/:id’, :controller => “admin”
and I would like to add a last line that will route everything else to
the function of a controlle
eg:
map.connect ‘*’, :controller => “main”, :action => “stuff”
of course this is not correct but this is the idea
I want /foo/bar/blahblah to be routed to the stuff method of main’s
controller
(and of course it will override the /404.htm in production mode)
Can someone help ? I asked #rubyonrails without success
Making my question short :
Is there a way to use kind of wilcards in routes ?
All my google searches leads me to a python implementation of rails
routes which supports wilcards :
http://routes.groovie.org/
Is there a way to do this in rails ???
Fabien Meghazi wrote:
Is there a way to use kind of wilcards in routes ?
Here’s a mapper to give each user a homepage with their own name in its
URL:
map.connect ‘*login’, :controller => ‘account’, :action => ‘home_page’
And here’s the first line of the home_page action:
user = User.find_by_login(params[:login].to_s)
So can’t you replaced the find_by_login with some kind of regular
expression, then redirect from its results? Note the path part appears
in
params[:login].
–
Phlip
Redirecting... ← NOT a blog!!!
map.connect ‘*login’, :controller => ‘account’, :action => ‘home_page’
Ok thanks, I was trying a star alone ‘*’ but indeed, ‘*path’ worked
fine, thanks !