# Newbie Routing Question /site/1/edit vs. /site/edit/1

**URL:** <https://www.ruby-forum.com/t/newbie-routing-question-site-1-edit-vs-site-edit-1/131659>\
**Category:** Rails\
**Created:** [March 12, 2008, 8:45am UTC](https://www.ruby-forum.com/t/newbie-routing-question-site-1-edit-vs-site-edit-1/131659 "2008-03-12T08:45:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Baz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c4cdca/32.png) [@Baz](https://www.ruby-forum.com/u/Baz)\
**Post date:** [March 12, 2008, 8:45am UTC](https://www.ruby-forum.com/t/newbie-routing-question-site-1-edit-vs-site-edit-1/131659/1 "2008-03-12T08:45:27Z")

</div>

I have a question about how URLs are created.

This happens with the edit action on the controller.

Instead of creating the URL as [http://site.com/edit/1](http://site.com/edit/1) it sticks the ID  
in  
the middle:  
[http://site.com/1/edit](http://site.com/1/edit)

Two questions:

1. What exactly is the reason behind this default?
2. How do I override it?

I’ve tried searching but I’m not sure what terminology that I should  
search  
for: “default route/routing”, “route edit”, etc…didn’t turn up  
anything  
useful.

ThanX in advance.

---

<div class="post-metadata">

**Author:** ![Baz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c4cdca/32.png) [@Baz](https://www.ruby-forum.com/u/Baz)\
**Post date:** [March 12, 2008, 9:07am UTC](https://www.ruby-forum.com/t/newbie-routing-question-site-1-edit-vs-site-edit-1/131659/2 "2008-03-12T09:07:48Z")

</div>

are you using restful routes? In any case, that’s quite strange… The  
default should be

:controller/:action/:id

You’re also missing the controller name for some reason.

is this a new rails application? Have you messed around with the  
routes file? Do all your urls for different controllers show up this  
same way? Are you using nested resources?

---

<div class="post-metadata">

**Author:** ![Baz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c4cdca/32.png) [@Baz](https://www.ruby-forum.com/u/Baz)\
**Post date:** [March 12, 2008, 9:13am UTC](https://www.ruby-forum.com/t/newbie-routing-question-site-1-edit-vs-site-edit-1/131659/3 "2008-03-12T09:13:06Z")

</div>

Baz wrote:

> Instead of creating the URL as [http://site.com/edit/1](http://site.com/edit/1) it sticks the ID  
> in  
> the middle:  
> [http://site.com/1/edit](http://site.com/1/edit)

This should be more like:

[http://site.com/controller/1/edit](http://site.com/controller/1/edit)

> 1. What exactly is the reason behind this default?

These are RESTful routes. Google for “rails REST routes” or “rails 2  
scaffolding” and you should get some useful info. Basically, it’s a way  
of treating your database objects as resources and performing actions on  
them. Many actions involve just the HTTP method (GET, POST, PUT,  
DELETE) (the verbs of the request) and either the controller name or the  
controller plus an object’s id field (the nouns of the request). The  
appended actions (like “edit” above) extend this “language”. This means  
that the resource is:

[http://site.com/controller/1](http://site.com/controller/1)

and the action to be performed is encoded in the HTTP method (possibly  
augmented by an appended action to the resource). To see how this is  
put together, run the following command from your application’s top  
level directory:

rake routes

> 1. How do I override it?

These resources are used when you have lines like this in your  
config/routes.rb file:

map.resources :controller

If you comment this out, you will see that there is a line later which  
reads:

map.connect ‘:controller/:action/:id’

which will then provide you with the form of URLs you are looking for.  
Running the rake command again will show the difference.

---

<div class="post-metadata">

**Author:** ![Baz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c4cdca/32.png) [@Baz](https://www.ruby-forum.com/u/Baz)\
**Post date:** [March 12, 2008, 2:20pm UTC](https://www.ruby-forum.com/t/newbie-routing-question-site-1-edit-vs-site-edit-1/131659/4 "2008-03-12T14:20:09Z")

</div>

Right on the money Mark. ThanX.

Yes, I was missing the [site.com/controller/edit/1](http://site.com/controller/edit/1)

ThanX

I don’t take it there is a way to scaffold without these?

eg. make it generate:  
link\_to ‘Show’, :action =\> ‘show’, :id =\> controller  
?

On Wed, Mar 12, 2008 at 3:13 AM, Mark B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
