# How to get "www.site.com/user1" address

**URL:** <https://www.ruby-forum.com/t/how-to-get-www-site-com-user1-address/172246>\
**Category:** Rails\
**Created:** [July 17, 2009, 12:55pm UTC](https://www.ruby-forum.com/t/how-to-get-www-site-com-user1-address/172246 "2009-07-17T12:55:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![szkizzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@szkizzer](https://www.ruby-forum.com/u/szkizzer)\
**Post date:** [July 17, 2009, 12:55pm UTC](https://www.ruby-forum.com/t/how-to-get-www-site-com-user1-address/172246/1 "2009-07-17T12:55:32Z")

</div>

Hi,

I am a newcomer to the Rails Front. Currently reading chapter 17 of  
Agile Web D. on Rails. But a burning question, that I would  
appreciate anyone being able to verify for me!

Here goes:

What I am hoping of trying to build is a site where I can have a page  
for individual entry in the database. So if it were users: I wanted to  
have a page in the the format: [www.example.com/user1](http://www.example.com/user1) AND  
[www.example.com/user2](http://www.example.com/user2) and display information pertaining to that  
particular user.

How would one go about doing that. Up until now reading in the book, it  
seems to indicate that I can only have a  
[www.example.com/~controller\_here~](http://www.example.com/~controller_here~).

Now I also have a faint clue that you can set a controller default(map  
root). If I was to do that, would I need to have a new controller for  
each user? That’s the issue because it does not seem much of a DRY way  
of getting this done.

Another quick add-on question that just came to my head while thinking  
about this, if I was to implement search functionality. Say  
[www.example.com/search/“whateverquery”](http://www.example.com/search/%22whateverquery%22). Is it still possible in that  
case to like redirect to the result …if it was “user1”  
([www.example.com/user1](http://www.example.com/user1)).

\_\_

I appreciate you taking the time to read through this question. Rest  
assured, I’m going at full speed to get the answer to these questions  
myself. Nothing else keeps me up at 3:53Am 🙂

Thank You,

---

<div class="post-metadata">

**Author:** ![szkizzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@szkizzer](https://www.ruby-forum.com/u/szkizzer)\
**Post date:** [July 17, 2009, 1:15pm UTC](https://www.ruby-forum.com/t/how-to-get-www-site-com-user1-address/172246/2 "2009-07-17T13:15:18Z")

</div>

Hi

> I can have a page  
> for individual entry in the database.

Did not understand that  
I think you better to start with an example

./script/generate scaffold User name:string

Then watch what happens in config/routes.rb app/models app/views  
app/controllers

> Now I also have a faint clue that you can set a controller default(map  
> root). If I was to do that, would I need to have a new controller for  
> each user?

example  
map.root :controller =\> ‘user’

Then what happens is your root page will be mapped to user controller’s  
index action And here you have to delete or rename public/index.html  
before doing this

Sijo

---

<div class="post-metadata">

**Author:** ![szkizzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@szkizzer](https://www.ruby-forum.com/u/szkizzer)\
**Post date:** [July 17, 2009, 1:49pm UTC](https://www.ruby-forum.com/t/how-to-get-www-site-com-user1-address/172246/3 "2009-07-17T13:49:11Z")

</div>

> Then what happens is your root page will be mapped to user controller’s  
> index action And here you have to delete or rename public/index.html  
> before doing this
> 
> Sijo

You sir, are my hero.

Thank You so much.

---

<div class="post-metadata">

**Author:** ![szkizzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@szkizzer](https://www.ruby-forum.com/u/szkizzer)\
**Post date:** [July 17, 2009, 4:01pm UTC](https://www.ruby-forum.com/t/how-to-get-www-site-com-user1-address/172246/4 "2009-07-17T16:01:27Z")

</div>

Vlad C. wrote:  
[…]

> You sir, are my hero.
> 
> Thank You so much.

Except that I don’t think Sijo’s suggestion will work, if I understand  
correctly. I think you need something in routes.rb (near the end) like

map.connect ‘/:username’, :controller =\> ‘users’, :action =\>  
‘show\_by\_name’

But I could be wrong. In any case, this shouldn’t be _too_ difficult.  
You may also need to override User#to\_param.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
