开发者

Rails 3: Remap user_path route with match rule

开发者 https://www.devze.com 2023-02-15 12:59 出处:网络
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 i

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

精彩评论

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