[英]rails 3: custom routes in routes.rb
我想获得用户链接: /chicago/123-olegpasko
。 在我的帮手中:
def users_path(user)
"/#{if user.city; user.city.name; else; "city";end}/#{user.to_param}"
end
我怎样才能创建正确的路线?
现在我有类似的东西:
match 'dontknow/:id' => 'users#show', :as => :users
另外看看演员阵容
在您的模型中简单添加以下行:
def to_param
"#{id}-#{name.parameterize}"
end
解决方案很简单:
match ':name/:id' => 'users#show', :as => :users
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.