Forum: Ruby on Rails Re: customizing map.resources for REST

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.
8310c5a7c769345114597bcdef111488?d=identicon&s=25 Ben Munat (Guest)
on 2007-02-10 00:41
(Received via mailing list)
Yeah... I'm totally struggling to grok resource routes too... seems like
they've totally blown the beautiful simplicity of the old url pattern
stuff out of the water.

Would love to hear an answer to this question!!!


Andy Triboletti wrote:
 > I want to customize map.resources so it uses a uid in the URL instead
 > of the database id.   The uid is a field on my object.
 > So I have map.resources :things in routes.rb and I can update a thing
 > by accessing POST /thing/1.  Instead I want to update the thing by
 > POST /thing/80ed14ce098affc2  The thing has an id of 1 and a uid of
 > 80ed14ce098affc2
 > Any options other then getting rid of map.resources and explicitly
 > defining all the REST routes?
 > Thanks
 > Andy
3726bda7f0d852f7e8296fb0d69aa9e0?d=identicon&s=25 Andy Triboletti (Guest)
on 2007-02-10 02:43
(Received via mailing list)
Found a solution and that is to override to_param on each of the
objects, so in the thing model I have

   def to_param

Then in things_controller I have

   def show
     @thing = Thing.find_by_uid(params[:id])

There's also a patch out at,
which allows you to use map.resources :things, :key => :uid and that
way you could just use


in your controller.

821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2007-02-10 02:57
(Received via mailing list)
On 2/9/07, Andy Triboletti <> wrote:
>    def show
> Andy

Just to make it clear, there's nothing in the resource routes that
prevent you from using an alternate field.  It all has to do with what
your controllers expect to find in the params[:id] parameter.

Rick Olson
This topic is locked and can not be replied to.