# Re: customizing map.resources for REST

**URL:** <https://www.ruby-forum.com/t/re-customizing-map-resources-for-rest/85099>\
**Category:** Rails\
**Created:** [February 10, 2007, 12:41am UTC](https://www.ruby-forum.com/t/re-customizing-map-resources-for-rest/85099 "2007-02-10T00:41:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![glenatron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@glenatron](https://www.ruby-forum.com/u/glenatron)\
**Post date:** [February 10, 2007, 12:41am UTC](https://www.ruby-forum.com/t/re-customizing-map-resources-for-rest/85099/1 "2007-02-10T00:41:04Z")

</div>

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!!!

b

Andy T. 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

---

<div class="post-metadata">

**Author:** ![glenatron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@glenatron](https://www.ruby-forum.com/u/glenatron)\
**Post date:** [February 10, 2007, 2:43am UTC](https://www.ruby-forum.com/t/re-customizing-map-resources-for-rest/85099/2 "2007-02-10T02:43:26Z")

</div>

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  
“#{uid}”  
end

Then in things\_controller I have

def show  
@thing = Thing.find\_by\_uid(params[:id])  
end

There’s also a patch out at [http://dev.rubyonrails.org/ticket/6814](http://dev.rubyonrails.org/ticket/6814),  
which allows you to use map.resources :things, :key =\> :uid and that  
way you could just use

Thing.find(:params:uid)

in your controller.

Andy

---

<div class="post-metadata">

**Author:** ![glenatron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@glenatron](https://www.ruby-forum.com/u/glenatron)\
**Post date:** [February 10, 2007, 2:57am UTC](https://www.ruby-forum.com/t/re-customizing-map-resources-for-rest/85099/3 "2007-02-10T02:57:28Z")

</div>

On 2/9/07, Andy T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 O.  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)
