# Custom URL/path for map.resources?

**URL:** <https://www.ruby-forum.com/t/custom-url-path-for-map-resources/105960>\
**Category:** Rails\
**Created:** [June 4, 2007, 11:25pm UTC](https://www.ruby-forum.com/t/custom-url-path-for-map-resources/105960 "2007-06-04T23:25:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 4, 2007, 11:25pm UTC](https://www.ruby-forum.com/t/custom-url-path-for-map-resources/105960/1 "2007-06-04T23:25:44Z")

</div>

Hi,

what should I do if I want to customize/get rid of the controller name  
that’s part of the URL generated by default by map.resources ?

What I mean is I would like : /posts/5  
to become: /5  
or: /blah/5

That must be a really easy thing to do, however I cannot figure out  
even by checking the API.

Thanks!

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 4, 2007, 11:32pm UTC](https://www.ruby-forum.com/t/custom-url-path-for-map-resources/105960/2 "2007-06-04T23:32:45Z")

</div>

Ok, I’ve found how to do it the non-RESTful way by adding this to my  
routes.rb

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

However, I’m wondering if there is a better way of doing it when using  
a RESTful design?

Thanks

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 5, 2007, 1:27am UTC](https://www.ruby-forum.com/t/custom-url-path-for-map-resources/105960/3 "2007-06-05T01:27:19Z")

</div>

What??

I must assume that your application has only one single resource, and  
will never have any more than that? I don’t see how this could be  
done in a truly RESTful way given that a major part of the REST URL is  
to identify the “resource” that you want to access. In your case that  
would be the Post resource (i.e. posts collection). Otherwise what  
meaning would /5 have? The 5th item in a collection of what?

Another option would be to use a named route, but that isn’t really  
RESTful either.

P.S. The “posts” in the URL is not really the controller name. It is  
the resource name/identifier. Read “GET: /posts/5” as GET the 5th  
item from the posts collection of Post resources.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 5, 2007, 1:35am UTC](https://www.ruby-forum.com/t/custom-url-path-for-map-resources/105960/4 "2007-06-05T01:35:20Z")

</div>

On 6/4/07, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> That must be a really easy thing to do, however I cannot figure out  
> even by checking the API.

Just use map.connect. Consider map.resources your reward for  
following conventions. In this case you’re not, so you’ll have to use  
map.connect. Also, just because you’re not following standard rails  
restful conventions doesn’t mean it’s not a REST service.  
map.resources sets up routes in a specific style, that’s all.

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 5, 2007, 3:47am UTC](https://www.ruby-forum.com/t/custom-url-path-for-map-resources/105960/5 "2007-06-05T03:47:34Z")

</div>

Thanks for the input. That makes sence and I must admit that I didn’t  
think about what I was doing 🙂
