[英]rails 3: custom routes in routes.rb
I want to get link to user like: /chicago/123-olegpasko
. 我想获得用户链接:
/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 查看有关friendly_url的Railcast
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.