Custom URL/path for map.resources ?

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!

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

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.

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.

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