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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:59:39+00:00 2026-05-31T19:59:39+00:00

Since the beginning I always hat this one problem with rails, short urls without

  • 0

Since the beginning I always hat this one problem with rails, short urls without the controller name.

For example, I have a blog and I don’t want any dates or controller names in the url, I already have a Page model with a unique field url in my database. Rails works great with such urls:

jeena.net/pages/1

And when I modify the model I even can get it to use

jeena.net/pages/foo

But it seems not to matter what I do I can not get it to work with just:

jeena.net/foo

Of course I want the index page still to work with

jeena.net/pages

And I want creating new pages and updating old pages to work too in some was as well as the link_to()-method. All suggestions are appreciated.

  • 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-31T19:59:40+00:00Added an answer on May 31, 2026 at 7:59 pm

    To define that route, try adding the following to your routes.rb:

    match '/:id' => 'your_controller#your_action'
    

    This will pretty much match everything to the id of your model. And that’s not very nice… You don’t want to route youe_host/pages to the pages controller, with an id equal to ‘pages’… To prevent that from happening, make sure to put that line on the end of the routes.rb file. The router uses the first route that matches the path received, so putting that line on the end of it will make sure that it will only match your route after it ran out of other meaningful options.

    A better practice would be to pass regexp constraints to the router, so that it will only match ids with a specific format, like that:

    match '/:id' => 'your_controller#your_action', :constraints => { :id => /your_regexp/ }
    

    Refer to the guides if you have doubts about the rails rounting system. It is pretty well written and covers lots of important things.

    Rails rounting – Official Guides

    edit: to create a named route, one that you can call in your controllers and override the normal routes that you are probably creating with resource, you have to provide the :as => parameter in your routes.rb

    match '/:id' => 'your_controller#your_action', :as => some_name
    

    Then you’ll be able to call it in your controller/views like this:

    link_to some_name_path(@my_string_id)
    

    Hope this helps. And take a time to read the guides, it has really lots of useful info, including more details about creating named routes.

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

Sidebar

Related Questions

Since beginning to use VB.NET some years ago I have become slowly familiar with
This bug may be lurking since the beginning of ruby-mode , but I noticed
We have been getting a new error in our Android app since beginning of
I have an iOS app built since the beginning with an error in it.
Since CS3 doesn't have a web service component, as previous versions had, is there
Since debate without meaningful terms is meaningless , I figured I would point at
Since the keyboard is the interface we use to the computer, I've always thought
Since Rails is not multithreaded (yet), it seems like a threaded web framework would
Not sure if this would be better suited for ServerFault, but since I am
since the beginning of my programmation, I used some special character like <-, <<

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.