user1606936
user1606936

Reputation: 5

Route redirection

Upon login, I would like a user to be directed to

example.com/me

and not

example.com/users/$ID_NUMBER

I've added the following to my routes.rb

match '/me', to: 'users#show'

And the users_controller

@user = current_user
redirect_to me_url

However, I get redirection loops. I can call example.com/me without any problem, but I cannot go directly there during the login step.

Upvotes: 0

Views: 56

Answers (1)

Kyle
Kyle

Reputation: 22258

You need to create the url helpers in your routes.rb

match '/me' => 'users#show', :as => :me

The :as => :me part is what creates the me_url and me_path helpers.

Rails routing

Upvotes: 1

Related Questions