开发者

Rails 3: Remap user_path route with match rule

I have got this in my routes file:

resources :users

match '/@:id' => 'users#show'

When I go to /@radeks then it would be the same as if I would go to /users/radeks. However, I use user_path in my views, but this points to /users/radek开发者_运维知识库s which I don't want.

How can I make user_path always point to /@:id?


Edit

I also have got this in my User model:

def to_param
  name
end


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

The :as argument makes this a "named route". See http://guides.rubyonrails.org/routing.html#naming-routes for more info.

NB that you're overriding the default 'user' named route you get automagically from 'resources :users'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜