简体   繁体   中英

rails 3: custom routes in routes.rb

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

Check out the Railcasts about friendly_url

Also take a look at the routes casts

Simple add this lines in you model:

def to_param
  "#{id}-#{name.parameterize}"
end

解决方案很简单:

match ':name/:id' => 'users#show', :as => :users

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM