Forum: Ruby on Rails catch-all routing

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Grayson P. (Guest)
on 2008-10-23 03:27
I know this isn't all that Rails friendly but is it possible to do
catch-all routing so that some value can be passed in as if it were a
controller for example

http://localhost:3000/ford/thunderbird
http://localhost:3000/gm/solstice

I know you can do it like this

http://localhost:3000/manufacturers/ford/thunderbird
http://localhost:3000/manufacturers/gm/solstice

but is it possible to skip the controller name?

TIA.

GP
Andrew B. (Guest)
on 2008-10-23 04:00
(Received via mailing list)
map.connect ":manufacturer_name/:model_name", :controller =>
"manufactuers", :action => "show"

in your controller params[:manufacturer_name] and params[:model_name]
should be available

On Oct 22, 6:27 pm, Grayson P. <removed_email_address@domain.invalid>
Grayson P. (Guest)
on 2008-10-23 06:23
Andrew,

Sorry I should have mentioned that I won't know the manufacturer names
ahead of time (in other words, I want to make it data driven).  That's
what I meant by catch-all.

Andrew B. wrote:
> map.connect ":manufacturer_name/:model_name", :controller =>
> "manufactuers", :action => "show"
>
> in your controller params[:manufacturer_name] and params[:model_name]
> should be available
>
> On Oct 22, 6:27�pm, Grayson P. <removed_email_address@domain.invalid>
Freddy A. (Guest)
on 2008-10-23 09:45
(Received via mailing list)
map.static ':permalink', :controller => 'pages', :action => 'show'

or

map.connect "*path", :controller => "four_oh_fours"

First on is not great and you need to handle 404s in that
controller... the second is well an example from a 404 controller BUT
it shows the *path example... if you do /bla1/bla2/bla3 that's what
you get in the params...

Parameters: {"action"=>"index", "controller"=>"four_oh_fours",
"path"=>["bla1", "bla2", "bla3"]}
This topic is locked and can not be replied to.