I am trying make a project in which /username gets redirected to that username's profile. How can I make this happen?
The route would be: "get /:username", to: "users#profile"
You would change users#profile
to whatever your controller action is called.
You need to make sure to put this at the end of your routes. Otherwise it will intercept all your routes.
For example, don't do the following:
get "/:username", to: "users#profile"
get "/foo", to: "pages#bar"
Because you will never be able to reach the pages#bar
endpoint.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With