Forum: Ruby on Rails Custom URL/path for map.resources ?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
682594f8bf31a07491a0044b4d81e55f?d=identicon&s=25 (Guest)
on 2007-06-04 23:25
(Received via mailing list)

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.

682594f8bf31a07491a0044b4d81e55f?d=identicon&s=25 (Guest)
on 2007-06-04 23:32
(Received via mailing list)
Ok, I've found how to do it the non-RESTful way by adding this to my

  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?

21f7ed21f11a809050594c82eab11d67?d=identicon&s=25 Robert Walker (Guest)
on 2007-06-05 01:27
(Received via mailing list)

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.
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2007-06-05 01:35
(Received via mailing list)
On 6/4/07, <> 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 Olson
682594f8bf31a07491a0044b4d81e55f?d=identicon&s=25 (Guest)
on 2007-06-05 03:47
(Received via mailing list)
Thanks for the input. That makes sence and I must admit that I didn't
think about what I was doing :-)
This topic is locked and can not be replied to.