Question

Currently I have a rails app where user profiles are viewed at "/users/:id", but I want to change that to "/:username". I've fixed the rails routes so that I have "match '/:username', :to => 'users#show', but I want to make it so I can easily use "redirect_to @user" within the controllers so that it goes to this new route. This still currently goes to "/users/:id".

How would I go about editing the default route?

Was it helpful?

Solution

If you add to your match line the following: ":as => user_path" I think it would work, but I don't know if it would conflict with the already existing one... probably created by devise...

A bit more on this: As far as I know (I may be wrong here), redirect_to @user, just calls user_path(@user). So if you create a new url helper called user_path, then it should work as you expect it to work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top