0

I am using a non-id parameter in one of my routes like so:

get 'users/:attribute' => 'users#special_action', :as => named_route

I like the named route thingy and I hoped I can just do:

named_route_url(@user)

To get a url, where the :attribute part gets replaced by user.attribute.

To my surprise, routing used what User.to_param provides.

While I can understand that this is a convention, I would like to know if there is a way to say I want to specificaly use attribute x in my route.

(Example of scenatio, where that might be of benefit is if I want to rename the attribute, but keep the route, I can just rename it in the route.)

4

0 回答 0