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 3960784
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:53:43+00:00 2026-05-20T02:53:43+00:00

I am running Ruby on Rails 3 and I would like to set up

  • 0

I am running Ruby on Rails 3 and I would like to set up my routes to show additional information in the URL using namespaces.

In the routes.rb file I have:

namespace "users" do
  resources :account
end

So, the URL to show an account page is:

http://<site_name>/users/accounts/1

I would like to rewrite/redirect that URL as/to

http://<site_name>/user/1/Test_Username

where “Test_username” is the username of the user. Also, I would like to redirect all URLs like

# "Not_real_Test_username" is a bad entered username of the user.
http://<site_name>/users/accounts/1/Not_real_Test_username

to the above.


At this time I solved part of my issuelike this:

  scope :module => "users" do
    match 'user/:id' => "accounts#show"
  end
  • 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-05-20T02:53:49+00:00Added an answer on May 20, 2026 at 2:53 am

    My apologies for not answering your question (@zetetic has done that well enough), but the best practice here is to stay within the RESTful-style Rails URL scheme except for rare exceptions. The way most people make pretty URLs in this way is to use a hyphen, e.g.:

    /accounts/1-username
    

    This does not require any routing changes. Simply implement:

    class Account < ActiveRecord::Base
      def to_param
        "#{self.id}-#{self.username}"
      end
    end
    

    And handle the extra string data in your finds by calling to_i.

    class AccountController < ApplicationController
       def show
         @account = Account.find(params[:id].to_i)
       end
    end
    

    When you do link_to 'Your Account', account_path(@account), Rails will automatically produce the pretty URL.

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

Sidebar

Related Questions

I'm looking at ways to deploy a Ruby on Rails app (running on JRuby)
I am running OS X 10.5, Ruby 1.8.6, Rails 2.1, sqlite3-ruby 1.2.2 and I
I am running Ruby and MySQL on a Windows box. I have some Ruby
Running a rails site right now using SQLite3. About once every 500 requests or
I am running ruby script/generate scaffold or ruby script/generate model and I know the
When running tests in Ruby's unit::test framework, is there a really easy way to
When I'm running a simple Ruby script, what's the easiest way to dump an
Is there an easy way to tell if a ruby script is already running
running git instaweb in my repository opens a page that says 403 Forbidden -
Running into a problem where on certain servers we get an error that the

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.