Skip to main content
Ask A Question
You’re not receiving notifications from this thread.
Subscribe style URLs for username

General • Asked by Nino Rosella

Hi everyone,

I'm implementing a username system in my app, and I'm trying to make the URLs pretty. I'd rather not have anything like:

but rather

If I want the pretty version I'm going to have to whitelist a whole load of paths, which I'd rather not do. I noticed that and do the following to solve this:

How do I go about creating the same in a Rails 6 app? Pretty sure I have to namespace the routes, but unsure how to implement it exactly.


I haven't tested it, but in your routes try:
get "/:username" => "user#show"

In your user controller:

  def show
    @user = User.where(username: params[:username])

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,353+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.