# How to use different key than :id in route?

**URL:** <https://www.ruby-forum.com/t/how-to-use-different-key-than-id-in-route/171644>\
**Category:** Rails\
**Created:** [July 7, 2009, 4:01am UTC](https://www.ruby-forum.com/t/how-to-use-different-key-than-id-in-route/171644 "2009-07-07T04:01:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![blacknight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c68b51/32.png) [@blacknight](https://www.ruby-forum.com/u/blacknight)\
**Post date:** [July 7, 2009, 4:01am UTC](https://www.ruby-forum.com/t/how-to-use-different-key-than-id-in-route/171644/1 "2009-07-07T04:01:45Z")

</div>

Okay, so I’m trying to have a URL like the following (which uses a key  
generated at random):

societies/6b241c631c6beaa89c889b9fb388caef9f617900ca1eff  
societies/6b241c631c6beaa89c889b9fb388caef9f617900ca1eff/edit

Where do I change the default behavior from using the ID, to another  
value of that object?

---

<div class="post-metadata">

**Author:** ![blacknight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c68b51/32.png) [@blacknight](https://www.ruby-forum.com/u/blacknight)\
**Post date:** [July 7, 2009, 7:32am UTC](https://www.ruby-forum.com/t/how-to-use-different-key-than-id-in-route/171644/2 "2009-07-07T07:32:37Z")

</div>

Ben W. wrote:

> Okay, so I’m trying to have a URL like the following (which uses a key  
> generated at random):
> 
> societies/6b241c631c6beaa89c889b9fb388caef9f617900ca1eff  
> societies/6b241c631c6beaa89c889b9fb388caef9f617900ca1eff/edit
> 
> Where do I change the default behavior from using the ID, to another  
> value of that object?

Did you try this in routes -

map.connect ‘societies/:something/edit’, :action=\>‘aaa’,  
:controller=\>‘ccc’

- example. societies/:rkey/edit

---

<div class="post-metadata">

**Author:** ![blacknight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c68b51/32.png) [@blacknight](https://www.ruby-forum.com/u/blacknight)\
**Post date:** [July 8, 2009, 9:11am UTC](https://www.ruby-forum.com/t/how-to-use-different-key-than-id-in-route/171644/3 "2009-07-08T09:11:35Z")

</div>

2009/7/7, Rails L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 

–  
Von meinen Mobilgerät aus gesendet

---

<div class="post-metadata">

**Author:** ![blacknight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c68b51/32.png) [@blacknight](https://www.ruby-forum.com/u/blacknight)\
**Post date:** [July 8, 2009, 9:14am UTC](https://www.ruby-forum.com/t/how-to-use-different-key-than-id-in-route/171644/4 "2009-07-08T09:14:31Z")

</div>

You can overwrite to\_param to return the random thing and use  
find\_by\_random\_thing params[:id] in your controller actions

2009/7/8, mike [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > > value of that object?
> > > 
> > > >
> 
> –  
> Von meinen Mobilgerät aus gesendet

–  
Von meinen Mobilgerät aus gesendet

---

<div class="post-metadata">

**Author:** ![blacknight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c68b51/32.png) [@blacknight](https://www.ruby-forum.com/u/blacknight)\
**Post date:** [July 10, 2009, 10:13pm UTC](https://www.ruby-forum.com/t/how-to-use-different-key-than-id-in-route/171644/5 "2009-07-10T22:13:56Z")

</div>

On Jul 7, 1:32 am, Rails L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Did you try this in routes -
> 
> map.connect ‘societies/:something/edit’, :action=\>‘aaa’,  
> :controller=\>‘ccc’
> 
> - example. societies/:rkey/edit

I’d like to avoid rewriting routes (I mean, I can do  
map.resources :societies)

I’ll try the to\_params, that one slipped my mind.
