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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:06:01+00:00 2026-06-05T11:06:01+00:00

I don’t understand the necessity for nested routes. There are many things about Rails

  • 0

I don’t understand the necessity for nested routes. There are many things about Rails routes that I DO understand.

Here is my simple setup in this Rails 3.2 application:

Categories habtm Products

In routes.rb:

resources :categories do
  member do
    get 'list_products_in'
    post 'add_to'
    post 'remove_from'
  end
end

resources :products

I have basically created a page from which to add products to a category. There is a select box at the top containing the products, and at the bottom is the list. To add a product to the list, you choose one from the select box and click the “Add” button. “add_to” is called via Ajax. Works great.

My problem is that to make this app degrade gracefully, I want it to work without Ajax also. But none of my routes work properly.

I know from the above that my custom routes are not expecting a product_id to be passed in addition to the category id. My question is, how can I add more parameters to my custom routes?

  • 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-05T11:06:04+00:00Added an answer on June 5, 2026 at 11:06 am

    You can use :variable segments in your routes to supply additional variable segments.

    For example, you could add a product_id segment to your add_to and remove_from routes:

    ...
    post 'add_to/:product_id'
    post 'remove_from/:product_id'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't think that I'm mad, I understand how php works! That being said. I
Don't think there's much to say, here's my code for (int i = 0;
Don't yell at me! i have seen many threads claiming that HTML cannot be
Don't freak out about the length of my post, it's pretty simple, I just
Don't know if there is a better way to do this, so that is
Don't know how to google for such, but is there a way to query
Don't be afraid to use any technical jargon or low-level explanations for things, please.
Don't overthink this - there's a very commonly used term and I ... have
Don't know what's wrong here, when I run the application it says Specified method
Don't know a whole lot about streams. Why does the first version work using

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.