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'
精彩评论