# Personalized URL -- route.rb

**URL:** <https://www.ruby-forum.com/t/personalized-url-route-rb/160546>\
**Category:** Rails\
**Created:** [February 17, 2009, 5:15pm UTC](https://www.ruby-forum.com/t/personalized-url-route-rb/160546 "2009-02-17T17:15:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://www.ruby-forum.com/u/Abhishek_shukla)\
**Post date:** [February 17, 2009, 5:15pm UTC](https://www.ruby-forum.com/t/personalized-url-route-rb/160546/1 "2009-02-17T17:15:38Z")

</div>

Hello Friends,  
I want to configure personalized url for e.g. -  
[http://localhost:3000/xyzhere](http://localhost:3000/xyzhere) xyz is a database value. Now for the  
same i have implemented the  
following syntax inside my route.rb file

map.url ‘/:name’, :controller =\> ‘controller\_name’, :action =\>  
‘action\_name’

But now when ever i run my application the action\_name.rhtml appears  
whereever i click.

So guys really confused any suggestion from your side?

Thanks  
Abhi

---

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://www.ruby-forum.com/u/Abhishek_shukla)\
**Post date:** [February 17, 2009, 5:20pm UTC](https://www.ruby-forum.com/t/personalized-url-route-rb/160546/2 "2009-02-17T17:20:21Z")

</div>

Abhi,

Do you want that off of the root path or something like  
[http://domain.com/people/robbyrussell](http://domain.com/people/robbyrussell) ?

These are generally referred to as permalinks.

Robby

On Tue, Feb 17, 2009 at 8:14 AM, Abhishek shukla [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> So guys really confused any suggestion from your side?
> 
> Thanks  
> Abhi
> 
> >

–  
Robby R.  
Chief Evangelist, Partner

PLANET ARGON, LLC  
design // development // hosting w/Ruby on Rails

> **[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://robbyonrails.com/](http://robbyonrails.com/)  
[http://twitter.com/planetargon](http://twitter.com/planetargon)  
aim: planetargon

+1 503 445 2457  
+1 877 55 ARGON [toll free]  
+1 815 642 4068 [fax]

---

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://www.ruby-forum.com/u/Abhishek_shukla)\
**Post date:** [February 17, 2009, 5:26pm UTC](https://www.ruby-forum.com/t/personalized-url-route-rb/160546/3 "2009-02-17T17:26:51Z")

</div>

Hey Robby  
Thanks for reply i want just after the domain name  
– [http://domain.com/robbyrussell](http://domain.com/robbyrussell)  
[http://domain.com/people/robbyrussell](http://domain.com/people/robbyrussell)

instead of  
[http://domain.com/people/robbyrussell](http://domain.com/people/robbyrussell)

And the robbyrussell [http://domain.com/people/robbyrussell](http://domain.com/people/robbyrussell) will be a  
dynamic value…

Though i tried the following code inside the route.rb

map.url ‘/:name’, :controller =\> ‘controller\_name’, :action =\>  
‘action\_name’

It’s work but for ever page the above mentioned action is getting called  
☹

Thanks  
Abhishek

---

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://www.ruby-forum.com/u/Abhishek_shukla)\
**Post date:** [February 17, 2009, 6:03pm UTC](https://www.ruby-forum.com/t/personalized-url-route-rb/160546/4 "2009-02-17T18:03:53Z")

</div>

Have you placed it at the end of your routes.rb file?

It’s easier if you show up some real code.

- 

Maurício Linhares  
[http://alinhavado.wordpress.com/](http://alinhavado.wordpress.com/) (pt-br) | [http://blog.codevader.com/](http://blog.codevader.com/)  
(en)

---

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://www.ruby-forum.com/u/Abhishek_shukla)\
**Post date:** [February 18, 2009, 12:30pm UTC](https://www.ruby-forum.com/t/personalized-url-route-rb/160546/5 "2009-02-18T12:30:46Z")

</div>

On Feb 17, 4:14 pm, Abhishek shukla [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello Friends,  
> I want to configure personalized url for e.g. -[http://localhost:3000/xyzherexyz](http://localhost:3000/xyzherexyz) is a database value. Now for the  
> same i have implemented the  
> following syntax inside my route.rb file
> 
> map.url ‘/:name’, :controller =\> ‘controller\_name’, :action =\> ‘action\_name’
> 
> But now when ever i run my application the action\_name.rhtml appears  
> whereever i click.

That sounds like its working.

map.name “/:name”, :controller =\> “people”, :action =\> “show”  
map.connect “:controller/:action.:format”

will see a url like “[http://localhost:3000/anything](http://localhost:3000/anything)”  
and match it to the first route.  
it will do the same for “[http://localhost:3000/admin](http://localhost:3000/admin)”

and hence always try and grab PeopleController#show

what you’d need to do is declare any important routes before that

eg.

map.admin “/admin”, :controller =\> “admin”  
map.name “/:name”, :controller =\> “people”, :action =\> “show”  
map.connect “:controller/:action.:format”

this will make sure that “[http://localhost:3000/admin](http://localhost:3000/admin)” goes to the  
right place.

My suggestion is if you’re just starting out in rails,  
keep it simple.

[http://localhost:3000/people/Abishek](http://localhost:3000/people/Abishek)

looks just as nice,  
but is much simpler for a newbie.

Enjoy.

---

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://www.ruby-forum.com/u/Abhishek_shukla)\
**Post date:** [February 18, 2009, 4:06pm UTC](https://www.ruby-forum.com/t/personalized-url-route-rb/160546/6 "2009-02-18T16:06:46Z")

</div>

Hey thanks guys its working  
i put the line @ the bottom…  
Regards  
Abhishek S.

---

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://www.ruby-forum.com/u/Abhishek_shukla)\
**Post date:** [February 18, 2009, 1:13pm UTC](https://www.ruby-forum.com/t/personalized-url-route-rb/160546/7 "2009-02-18T13:13:05Z")

</div>

Make sure you put this near the bottom of routes.rb.

map.person ‘/:name’, :controller =\> ‘people’, :action =\> ‘show’

Then in your view…

\<%= link\_to “Person Name”, person\_path(“jimmy”) %\>

I don’t think this is the ideal situation, but it’ll do what you’re  
looking to have done. Really you should be using a named resource, and  
set the “to\_param” value in your person model to “name”.
