Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9242553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:36:12+00:00 2026-06-18T08:36:12+00:00

How do I route to a page that ends with an id? E.G. before:

  • 0

How do I route to a page that ends with an id?

E.G. 
before: site.com/messages/8
after:  site.com/messages/terrytibbs

I’ve tried:

match "/messages/:username" => "messages#id"

No luck so far. Just trying to make the url have a little more meaning by replacing the number with the username of the user the current user is talking to.

Kind regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:36:13+00:00Added an answer on June 18, 2026 at 8:36 am

    If you want something simple without having to change your routes etc, why not do this:

    class Message
    
      def to_param
        "#{id}-{username}"
      end
    
    ...
    end
    

    Assuming you have a username attribute on your message. That will make your url look like:

    site.com/messages/8-terrytibbs

    this works because of the following (say in irb):

    “8-terrytibbs”.to_i
    => 8

    and when rails looks up your message in your controller it will do the same thing to the id parameter.

    EDIT: there is an excellent railscast on this here: http://railscasts.com/episodes/63-model-name-in-url and an updated version here: http://railscasts.com/episodes/63-model-name-in-url-revised

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to setup a route so that if the user goes to http://mysite.com/page.html
I have a route like following, ideally I would like it to match: domain.com/layout/1-slug-is-the-name-of-the-page
I'm trying to generate an actionlink on a page that has the following route:
I would like to create a route for my MVC page that looks like
I was on a page that redirected me to my own web server (www.myserver.com)
I currently have a site that hosts a page that I want to both
I'm trying to write a simple rule such that: /page gets implicitly routed to
I need a codeigniter route so all of the following urls: admin/users/page/:num admin/accounts/page/:num members/results/page/:num
I have my views render to route requests like /controller/action (for instance, /Page/Create), so
Zend Route issue. Normally it works fine. http://www.example.com/course-details/1/Physics-Newtons-Law But if I type in an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.