Take the 2-minute tour ×

I want to get link to user like: /chicago/123-olegpasko . In my helper:

def users_path(user)
  "/#{if user.city; user.city.name; else; "city";end}/#{user.to_param}"

How can I create a right routes?

Now I have something like:

match 'dontknow/:id' => 'users#show', :as => :users
share|improve this question

3 Answers 3

Check out the Railcasts about friendly_url

Also take a look at the routes casts

share|improve this answer
Thanks! Links are useful, but not for my situation :) –  ANATHEM Apr 16 '12 at 20:49
Sorry, i didn't read your question correctly! –  Justin D. Apr 16 '12 at 21:49

Simple add this lines in you model:

def to_param
share|improve this answer
Thanks, but with my to_param is all Ok. My problem is in user.city. When I click to user link I getting route error. –  ANATHEM Apr 15 '12 at 8:13
up vote 0 down vote accepted

The solution was simple:

match ':name/:id' => 'users#show', :as => :users
share|improve this answer

Your Answer


