Routing question

I would like to create a route as follow:

map.connect ‘user/:user/profile’, :controller => “account”, :action =>
“profile”, :id => some_id

With this, I’m assuming when user put following address in the address


then it redirects to http://localhost/account/profile/1 (e.g. 1 is
user’s internal id)

What I don’t understand is how to convert user name to user id.

Set your route like this:

map.connect ‘user/:user/profile’, :controller => “account”, :action
=> “profile”

Write your profile action like this:

def profile
@user = User.find_by_name(params[:user])


The ID isn’t used at all. You must make your user name be unique for
this to work correctly.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs