# Custom URL routing based on usernames

**URL:** <https://www.ruby-forum.com/t/custom-url-routing-based-on-usernames/86290>\
**Category:** Rails\
**Created:** [February 21, 2007, 5:51am UTC](https://www.ruby-forum.com/t/custom-url-routing-based-on-usernames/86290 "2007-02-21T05:51:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [February 21, 2007, 5:51am UTC](https://www.ruby-forum.com/t/custom-url-routing-based-on-usernames/86290/1 "2007-02-21T05:51:48Z")

</div>

Hi all,

I have an application which has a number of users, each with their own  
usernames. I am able to setup URLrouting where I can do something like

> **[应用宝官网-全网最新最热手机应用游戏下载](https://sj.qq.com)**
>
> 应用宝是腾讯旗下官方手机app应用商店，致力于为您提供海量、优质、安全、最新的安卓应用游戏下载！

and that to call a chosen controller, action and passing charlie63 as  
the id. So that’s fine.

This is probably a stupid question, but to prevent problems, do I  
simply have to have a list of unavailable usernames and not allow  
people to create accounts with those as usernames? In other words, if  
I have a controller named, checkout, I need to not allow anyone to  
create a user name checkout, because when she tried to access her  
account through her URL [应用宝官网-全网最新最热手机应用游戏下载](http://myapp.com/checkout) it will actually go  
to controller: checkout and action: index?

If this is so, do I just need to manually maintain a list of invalid  
user names and check against those? Or can I call something in Rails  
to help me to look for existing controllers? Although, I guess I have  
to be careful because someone may create an account, use that for a  
while, and later on I may come along and create a controller with the  
same username.

Any help in getting something like this going, pointers, would be  
greatly appreciated.

Cheers,  
Diego

---

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [February 21, 2007, 6:48am UTC](https://www.ruby-forum.com/t/custom-url-routing-based-on-usernames/86290/2 "2007-02-21T06:48:51Z")

</div>

OK, think I’ve got it. I just need to place the routing rules for the  
username before the standard controller/action/id one which is there  
by default with a Rails app. So, even if I have a username with the  
same name as a controller, it will be found if it exists. Otherwise  
the controller’s routing rule will be evaluated.

---

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [February 21, 2007, 7:29am UTC](https://www.ruby-forum.com/t/custom-url-routing-based-on-usernames/86290/3 "2007-02-21T07:29:53Z")

</div>

Diego wrote:

> OK, think I’ve got it. I just need to place the routing rules for the  
> username before the standard controller/action/id one which is there  
> by default with a Rails app. So, even if I have a username with the  
> same name as a controller, it will be found if it exists. Otherwise  
> the controller’s routing rule will be evaluated.

You can take it a step further and use our resource hacks plugin for  
Rails. 🙂

One of our developers recently blogged about it.

- [http://blog.imperialdune.com/2007/2/13/pretty-urls-with-restful-rails](http://blog.imperialdune.com/2007/2/13/pretty-urls-with-restful-rails)

Cheers,

-Robby

–  
Robby R.

> **[Planet Argon](https://www.planetargon.com/)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

[http://www.robbyonrails.com/](http://www.robbyonrails.com/)

---

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [February 21, 2007, 7:38am UTC](https://www.ruby-forum.com/t/custom-url-routing-based-on-usernames/86290/4 "2007-02-21T07:38:54Z")

</div>

Thanks Robby, I’ll check it out.
