Transform URLs from: "url.com/Bob+Doe" to "url.com/bob_doe"

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” – and I’m
looking to get it in this format: “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.

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. [email protected]

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 [email protected] 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.