Understand rails routing

Hello,

I’m new to rails so this will be a noob question.

Let’s say I scaffold sth. named “foos”.

Rails generates a controller named foos_controller.rb with index,
show, new, edit, create, update and destroy.

The routes.rb contains

map.resources :foos
map.connect ‘:controller/:action/:id’
map.connect ‘:controller/:action/:id.:format’

So, by visiting “/foos/new” I can create a new “foo”. By visiting /
foos/new/1 I get routed to the show action with the parameter id=1
that shows the contents of this object. Okay, i get that.

But, what happens when I go to “/foos/1/edit”. This is not matching
“map.connect ‘:controller/:action/:id’” since action and id are
switched. Is scaffold doing some magic here, that I can’t find in the
sources? When I add a method, say “my_edit” with the exact content of
the “edit” method, i get “Unknown action No action responded to 1.”,
what I expected because my URI is not matching the map.connect in the
routes.rb.

Short questions:
How does rails know the routing of /foos/1/edit without the
map.connect?
When i want to create something like that, how do I do that?

Sorry for my poor english.

Greetings from germany.

got_nil

On Apr 26, 10:58 pm, got_nil [email protected]
wrote:

map.connect?
When i want to create something like that, how do I do that?

map.resources is short hand for defining a bunch of routes. See
Rails Routing from the Outside In — Ruby on Rails Guides for more details

Fred