# REST: using a different field than id

**URL:** <https://www.ruby-forum.com/t/rest-using-a-different-field-than-id/142507>\
**Category:** Rails\
**Created:** [July 8, 2008, 5:18pm UTC](https://www.ruby-forum.com/t/rest-using-a-different-field-than-id/142507 "2008-07-08T17:18:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![roland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3ab097/32.png) [@roland](https://www.ruby-forum.com/u/roland)\
**Post date:** [July 8, 2008, 5:18pm UTC](https://www.ruby-forum.com/t/rest-using-a-different-field-than-id/142507/1 "2008-07-08T17:18:21Z")

</div>

Hi,

I have a simple question: When constructing restful urls with something  
like

edit\_user\_path @user

I would like the route to be /user/username/edit instead of /user/1/edit

Now, I can do it with edit\_user\_path(@user.username), but i just don’t  
like it.

Is there a config place that can customize the chosen field?

Thanks,

Roland

---

<div class="post-metadata">

**Author:** ![roland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3ab097/32.png) [@roland](https://www.ruby-forum.com/u/roland)\
**Post date:** [July 8, 2008, 5:45pm UTC](https://www.ruby-forum.com/t/rest-using-a-different-field-than-id/142507/2 "2008-07-08T17:45:11Z")

</div>

On 8 Jul 2008, at 16:18, Roland M. wrote:

> edit
> 
> Now, I can do it with edit\_user\_path(@user.username), but i just don’t  
> like it.

Does overriding to\_param on User to return username do the trick?

Fred

---

<div class="post-metadata">

**Author:** ![roland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3ab097/32.png) [@roland](https://www.ruby-forum.com/u/roland)\
**Post date:** [July 8, 2008, 6:40pm UTC](https://www.ruby-forum.com/t/rest-using-a-different-field-than-id/142507/3 "2008-07-08T18:40:35Z")

</div>

Perfect. Thank you!
