# Make routes with e-mail address

**URL:** <https://www.ruby-forum.com/t/make-routes-with-e-mail-address/132294>\
**Category:** Rails\
**Created:** [March 18, 2008, 9:19pm UTC](https://www.ruby-forum.com/t/make-routes-with-e-mail-address/132294 "2008-03-18T21:19:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![makire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@makire](https://www.ruby-forum.com/u/makire)\
**Post date:** [March 18, 2008, 9:19pm UTC](https://www.ruby-forum.com/t/make-routes-with-e-mail-address/132294/1 "2008-03-18T21:19:37Z")

</div>

Hi

I have a RESTful controller that works when using a numeric ID. Now I  
would like to accept user login names as ID and for some of the cases  
this is an e-mail address. In short it boils down to routing the  
request URL

GET /users/removed\_email\_address@domain.invalid  
DELETE /users/removed\_email\_address@domain.invalid

to

:controller =\> :users, :action =\> :show  
:controller =\> :users, :action =\> :delete

And so on. Does anyone know how to do this. Grateful for any insight  
on this.

/Erik

---

<div class="post-metadata">

**Author:** ![makire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@makire](https://www.ruby-forum.com/u/makire)\
**Post date:** [March 18, 2008, 11:48pm UTC](https://www.ruby-forum.com/t/make-routes-with-e-mail-address/132294/2 "2008-03-18T23:48:49Z")

</div>

There’s no reason why you couldn’t just pass those as the ids to the  
url helpers, but you need to update your controller

user = User.find(params[:id])  
to  
user = User.find\_by\_email(params[:id])

---

<div class="post-metadata">

**Author:** ![makire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@makire](https://www.ruby-forum.com/u/makire)\
**Post date:** [March 20, 2008, 8:00pm UTC](https://www.ruby-forum.com/t/make-routes-with-e-mail-address/132294/3 "2008-03-20T20:00:43Z")

</div>

Hi and thanks for the input. The problem was that I wanted to use .xml  
as :format which was not possible without customized routes. I did  
some reading and came up with a solution which I post if anyone else  
has a similar problem:

map.connect “customers/:login.:format”,  
:controller =\> “customers”,  
:action =\> “show”,  
:conditions =\> {:method =\> :get},  
:login =\> /\b[\w.%-]+@[\w.%-]+.[a-zA-Z]{2,4}/

Kindest regards

Erik

On 18 Mar, 23:48, “removed\_email\_address@domain.invalid” \<ESPN3.DL-
