Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Specifying id in routes

#5280

I am trying to specify the id parameter in the new routes interface.

An example use is if I have a table of pages in a database, and I want to give one a fixed url, pointing to the standard show method with the entry's id.

So, if I want a one-off route for the privacy policy page (e.g. page 10), I would ideally want a route like this:

match "/privacy" => "pages#show#10", :as => "privacy_page"

The next best case would be:

match "/privacy" => "pages#show", :as => "privacy_page", :defaults => {:id => 10}

However, neither of these work and I am having to resort to:

match "/privacy(/:id)" => "pages#show", :as => "privacy_page", :defaults => {:id => 10}

I've looked through the source and don't think I'm missing anything obvious.

Thanks,
iHiD

Reported by iHiD · August 3rd, 2010 @ 12:43 AM

State: stale
Milestone: none
Assigned to: Andrew White Andrew White
Importance: Low

Activity

  1. Rohit Arondekar
    Rohit Arondekar
    • Assigned user set to Andrew White
    • Importance changed from to Low

    October 7th, 2010 @ 06:35 AM

  2. Andrew White
    Andrew White
    • State changed from new to needs-more-info

    Works as expected for me in 3.0.0:

    
      # Explicit
      match '/privacy', :to => 'pages#show', :as => :privacy, :via => :get, :defaults => { :id => 10 }
    
      # Shorthand
      get '/privacy' => 'pages#show', :id => 10
    

    iHiD, can you confirm that it's fixed for you?

    October 7th, 2010 @ 07:03 AM

  3. Santiago Pastorino
    Santiago Pastorino
    • State changed from needs-more-info to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:58 PM

  4. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:58 PM