# Understand rails routing

**URL:** <https://www.ruby-forum.com/t/understand-rails-routing/187624>\
**Category:** Rails\
**Created:** [April 27, 2010, 12:08am UTC](https://www.ruby-forum.com/t/understand-rails-routing/187624 "2010-04-27T00:08:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![got\_nil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bc8723/32.png) [@got\_nil](https://www.ruby-forum.com/u/got_nil)\
**Post date:** [April 27, 2010, 12:08am UTC](https://www.ruby-forum.com/t/understand-rails-routing/187624/1 "2010-04-27T00:08:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![got\_nil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bc8723/32.png) [@got\_nil](https://www.ruby-forum.com/u/got_nil)\
**Post date:** [April 27, 2010, 12:11am UTC](https://www.ruby-forum.com/t/understand-rails-routing/187624/2 "2010-04-27T00:11:51Z")

</div>

On Apr 26, 10:58 pm, got\_nil [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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](http://guides.rubyonrails.org/routing.html) for more details

Fred
