Reputation: 2911
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}"
end
How can I create a right routes?
Now I have something like:
match 'dontknow/:id' => 'users#show', :as => :users
Upvotes: 0
Views: 536
Reputation: 2911
The solution was simple:
match ':name/:id' => 'users#show', :as => :users
Upvotes: 0
Reputation: 7160
Simple add this lines in you model:
def to_param
"#{id}-#{name.parameterize}"
end
Upvotes: 1
Reputation: 4976
Check out the Railcasts about friendly_url
Also take a look at the routes casts
Upvotes: 1