# Routing a restful controller to work from site root

**URL:** <https://www.ruby-forum.com/t/routing-a-restful-controller-to-work-from-site-root/108776>\
**Category:** Rails\
**Created:** [July 6, 2007, 10:08pm UTC](https://www.ruby-forum.com/t/routing-a-restful-controller-to-work-from-site-root/108776 "2007-07-06T22:08:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![etikette](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/43a26b/32.png) [@etikette](https://www.ruby-forum.com/u/etikette)\
**Post date:** [July 6, 2007, 10:08pm UTC](https://www.ruby-forum.com/t/routing-a-restful-controller-to-work-from-site-root/108776/1 "2007-07-06T22:08:35Z")

</div>

hi i have rewritten my map.resources so that a resource is called from  
the start: map.connect ‘’, :controller =\> “resource”

so [www.mysite.com](http://www.mysite.com) lists the available resource

however i want [www.mysite.com/1](http://www.mysite.com/1) to show one of a particular resource  
rather than [www.mysite.com/show/1](http://www.mysite.com/show/1) as is the default restful route.

how can i get this url?

thanks

---

<div class="post-metadata">

**Author:** ![etikette](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/43a26b/32.png) [@etikette](https://www.ruby-forum.com/u/etikette)\
**Post date:** [July 6, 2007, 10:41pm UTC](https://www.ruby-forum.com/t/routing-a-restful-controller-to-work-from-site-root/108776/2 "2007-07-06T22:41:39Z")

</div>

this is great but what about with nested resources?

thanks

On Jul 6, 9:19 pm, Michael M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![etikette](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/43a26b/32.png) [@etikette](https://www.ruby-forum.com/u/etikette)\
**Post date:** [July 6, 2007, 10:19pm UTC](https://www.ruby-forum.com/t/routing-a-restful-controller-to-work-from-site-root/108776/3 "2007-07-06T22:19:17Z")

</div>

Marc Rice wrote:

> hi i have rewritten my map.resources so that a resource is called from  
> the start: map.connect ‘’, :controller =\> “resource”
> 
> so [www.mysite.com](http://www.mysite.com) lists the available resource
> 
> however i want [www.mysite.com/1](http://www.mysite.com/1) to show one of a particular resource  
> rather than [www.mysite.com/show/1](http://www.mysite.com/show/1) as is the default restful route.
> 
> how can i get this url?

map.connect ‘:id’, :controller =\> “resources”, :action=\>“show”

---

<div class="post-metadata">

**Author:** ![etikette](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/43a26b/32.png) [@etikette](https://www.ruby-forum.com/u/etikette)\
**Post date:** [July 7, 2007, 9:13am UTC](https://www.ruby-forum.com/t/routing-a-restful-controller-to-work-from-site-root/108776/4 "2007-07-07T09:13:17Z")

</div>

A few things in you post don’t make sense to me…

1. You say that [www.mysite.com/show/1](http://www.mysite.com/show/1) is a “RESTful route,” but it’s  
not. RESTful routes don’t include the action (show) in this case.  
Say if your resource/model was Post then the RESTful URL would look  
something like [www.mysite.com/posts/1](http://www.mysite.com/posts/1). Notice there’s no mention of  
the action. The action is based on the HTTP verb used to access the  
URL. Show would be a GET request, POST to create, PUT to update,  
DELETE to destroy.

2. If you are using RESTful routes you would use map.resources not  
map.connect to declare your resources, which in turn creates the  
RESTful URLs.

3. If what you really mean is that you want to drop the resource out  
of the URL, which I must assume your application has only one main  
resource and everything else in the database is nested, then you would  
need to use map.connect or a named route to do that.
