# RESTful Routing: Getting names of resources out of paths

**URL:** <https://www.ruby-forum.com/t/restful-routing-getting-names-of-resources-out-of-paths/165877>\
**Category:** Rails\
**Created:** [April 18, 2009, 8:11pm UTC](https://www.ruby-forum.com/t/restful-routing-getting-names-of-resources-out-of-paths/165877 "2009-04-18T20:11:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [April 18, 2009, 8:11pm UTC](https://www.ruby-forum.com/t/restful-routing-getting-names-of-resources-out-of-paths/165877/1 "2009-04-18T20:11:30Z")

</div>

Hello -

I’m trying to remain RESTful in a new application that I’m building, but  
I’m not sure how to get the routes that I want. I’m trying to avoid  
having resource names like “posts” and “comments” cluttering things up.

For example, for a resource that I designate:

GET [example.com](http://example.com) → index  
GET [example.com/1](http://example.com/1) → show, id=1  
GET [example.com/1/edit](http://example.com/1/edit) → edit, id=1  
GET [example.com/new](http://example.com/new) → new

Etc. In addition, I’d like to nest another resource beneath that  
(there’s a has\_many relationship), so that I can get routes like:

[example.com/1/3](http://example.com/1/3)  
[example.com/1/3/edit](http://example.com/1/3/edit)

Etc. I’m planning on using friendly\_id to change the IDs and make the  
URLs more memorable, but before I introduce that I just want to get  
those resource names out of there. I want to remain as restful as  
possible, but I’m not sure how to get this using map.resources.

Ideas?

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [April 21, 2009, 4:00pm UTC](https://www.ruby-forum.com/t/restful-routing-getting-names-of-resources-out-of-paths/165877/2 "2009-04-21T16:00:35Z")

</div>

Hi Chris,

You can’t do it using Rails’ map.resources macro. You need to use the  
router directly, like this:

map.posts ‘’, :controller =\> ‘posts’, :action =\> ‘index’, :conditions  
=\> {:method =\> :get}  
map.posts ‘’, :controller =\> ‘posts’, :action =\> ‘create’, :conditions  
=\> {:method =\> :post}  
map.new\_post ‘new’, :controller =\> ‘posts’, :action =\>  
‘new’, :conditions =\> {:method =\> :get}  
map.post ‘:id’, :controller =\> ‘posts’, :action =\> ‘show’, :conditions  
=\> {:method =\> :get}  
map.post ‘:id’, :controller =\> ‘posts’, :action =\>  
‘update’, :conditions =\> {:method =\> :put}  
map.post ‘:id’, :controller =\> ‘posts’, :action =\>  
‘destroy’, :conditions =\> {:method =\> :delete}  
map.edit\_post ‘:id/edit’, :controller =\> ‘posts’, :action =\>  
‘edit’, :conditions =\> {:method =\> :get}  
map.resources :comments, :path\_prefix =\> ‘:post\_id’

it will work, but generally it’s not a very good idea to have such  
URLs, cause it won’t work very well if you will have lots of resources  
at some point. Maybe it will be better to use standard routes + 2  
aliases, for index (/ — shows all posts) and for show (/123 - shows a  
specific post).

Dmitry
