# Transform URLs from: "url.com/Bob+Doe" to "url.com/bob\_doe"

**URL:** <https://www.ruby-forum.com/t/transform-urls-from-url-com-bob-doe-to-url-com-bob-doe/109899>\
**Category:** Rails\
**Created:** [July 20, 2007, 12:51am UTC](https://www.ruby-forum.com/t/transform-urls-from-url-com-bob-doe-to-url-com-bob-doe/109899 "2007-07-20T00:51:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [July 20, 2007, 12:51am UTC](https://www.ruby-forum.com/t/transform-urls-from-url-com-bob-doe-to-url-com-bob-doe/109899/1 "2007-07-20T00:51:26Z")

</div>

Is that possible, and would you know how I can do that?

I’m creating individual pages for users based on their first and last  
names.

In my routes.rb, I have:

map.client ‘:user\_full\_name’, :controller =\> ‘user’, :action =\>  
‘individual\_user\_page’

Then in my controller, I have:

def individual\_user\_page  
@user = User.find(:first, :conditions =\> [‘first\_name = ?’,  
params[:user\_full\_name]])  
render :layout =\> “user\_page”  
end

Right now, the url is in this format: “[url.com/Bob+Doe](http://url.com/Bob+Doe)” – and I’m  
looking to get it in this format: “[url.com/bob\_doe](http://url.com/bob_doe)”

I googled for some time, and still have no idea where to start. Any help  
would be great appreciated. Thank you.

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [July 20, 2007, 2:39am UTC](https://www.ruby-forum.com/t/transform-urls-from-url-com-bob-doe-to-url-com-bob-doe/109899/2 "2007-07-20T02:39:22Z")

</div>

If you are using Apache HTTP Server they have some nice URL rewrite  
stuff. Of course you will still need to tell rails what controller  
you want. I’m new to Rails though so maybe there is a Rails specific  
way to do this. My personal bias is towards letting Apache take care  
of any massive amount of URL rewriting.

On Jul 19, 6:51 pm, Bob S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [July 20, 2007, 5:09pm UTC](https://www.ruby-forum.com/t/transform-urls-from-url-com-bob-doe-to-url-com-bob-doe/109899/3 "2007-07-20T17:09:31Z")

</div>

This got me to for a while. The method you are looking for is  
underscore. It takes a string as a parameter and out puts it like  
you  
want it. After that, you can parse how you need to search in the  
database.

HTH,  
Richard

On 7/19/07, schof [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Is that possible, and would you know how I can do that?
> > 
> > would be great appreciated. Thank you.
> > 
> > –  
> > Posted viahttp://www.ruby-forum.com/.
> 
> >

–  
Richard J Hancock  
Developer/System A.
