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

  • Home
  • SEARCH
  • 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 9228285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:17:04+00:00 2026-06-18T05:17:04+00:00

Currently using friendly_id on my messages table. Messages are accessed like this: site.com/messages/id e.g.

  • 0

Currently using friendly_id on my messages table. Messages are accessed like this:

site.com/messages/id e.g. site.com/messages/8

I’d like to use it like this:

site.come/messages/username e.g. site.com/messages/terrytibbs

I’ve got the gem working fine as I tested it with the “body” attribute in my messages table. Sent a short message “test” and tried to access it using site.com/messages/test and it works fine.

However I need to use users usernames to do this. I was wondering if there is a way to access another models attribute as my usernames are stored in my users table. I could always create a username column in my messages table and have their usernames saved there but don’t like the idea of having another username column when I already have one.

Since my tables are linked I can easily find out the message sender or recipients username using their sender_id or recipient_id as that matches their ID in my users table.

Is there a quick and easy way to do what I want to do or will I have to resort to creating a username column in my messages table?

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-18T05:17:05+00:00Added an answer on June 18, 2026 at 5:17 am

    @sevenseacat is right but I believe you would have a route conflict that way:

    /messages/:id
    /messages/:username
    

    Perhaps the route should be more like /user/:id/messages which would be a nested route of messages under user

    resources :users do
      resources :messages, only: [:index]
    end
    

    Run rake routes to see the generated route. In your MessagesController, you will receive :user_id and easily be able to call:

    User.find(params[:user_id]).messages
    

    Make sure you have has_many :messages working in your User model.

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

Sidebar

Related Questions

My (rails 3.1) site currently does routing for objects using ids like so: /object/show/:id
Currently using MySQL version 5.1.6 This is my first real world build and so
I am working on making my site more SEO friendly I am currently using
Using: Rails: 3.0.3 Friendly_id: 3.2.1 I am building a website with (currently) two locales,
I am currently coding a pagination script into many parts of my site, this
Currently using the HTTPServletRequest class and specifically the .getQueryString method to retrieve an inputted
Currently using Google Analytics as a supplement to our paid tracking software, but neither
Currently using Xcode 4.2 and I have two view controllers (1 and 2). I
I currently using android NDK to write some native code in C. I have
I'm currently using the NEST ElasticSearch C# Library for interacting with ElasticSearch. My project

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.