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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:45:02+00:00 2026-05-28T00:45:02+00:00

I have searched and searched and I cannot find a page which spells out

  • 0

I have searched and searched and I cannot find a page which spells out the syntax of routes.rb in Rails 3. There are guidelines, overviews, even advanced examples but why isn’t there a page that spells out the exact syntax of each keyword?? This page

http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/

contains a lot of advanced examples but doesn’t take the time to discuss the behavior of all the examples given. I would appreciate it if someone could point me to a page that breaks down the syntax of routes.rb.

Here is the problem I am trying to solve. I have two models modelA and modelB. The relationship is modelA has_many modelB and modelB belongs_to modelA. I created the controller for modelB under namespace of modelA. So in my rails app folder, I have

app/controllers/modelA_controller.rb
app/controllers/modelA/modelB_controller.rb

I want my routes to be as such:

http://localhost:3000/modelA/:modelA_id/modelB/  [index]
http://localhost:3000/modelA/:modelA_id/modelB/:modelB_id  [show]
etc.

I tried the following in routes.rb and none of it works:

resources :modelA do
  resources :modelB
end
--
resources :modelA do
  member do
    resources :modelB
  end
end
--
namespace :modelA do
  resources :modelB
end
--
match '/modelA/:modelA_id/modelB/action', :to => '/modelA/modelB#action'

I know some of the things I tried are obviously wrong but when you have spent 2 days on a single problem, anything goes!

  • 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-28T00:45:02+00:00Added an answer on May 28, 2026 at 12:45 am

    The reason no one has a “definitive” guide on routing syntax is that it is pretty flexible so you could probably write a few chapters just on that one subject. However, I would recommend: http://guides.rubyonrails.org/routing.html

    From your question, it sounds like you’re namespacing modelB under modelA but you also want the id for modelA to be within the route itself.

    So if your ModelBController looks something like:

    class ModelA::ModelBController < ApplicationController
      # controller code here
    end
    

    then you can just do:

    resources :modelA do
      resources :modelB, :module => :modelA
    end
    

    However, are you sure you want to namespace the controller like that? If you just want nested resources like a typical has_many relationship, you don’t need to be namespacing modelB under modelA.

    Instead, you’d have:

    /app
      /controllers
        /modelA
          # some files
        /modelB
          # some files
    

    And your modelB controller would be:

    class ModelBController < ApplicationController
      # controller code here
    end
    

    Then you could do

    resources :modelA do
      resources :modelB
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, I have searched and searched and cannot find a single person who has
I have searched the web but I cannot find the solution to my problem.
I have searched all morning and yesterday afternoon and still cannot find an solution
I have searched but cannot find the jQuery selector that gets an element by
I have searched Codeplex, NuGet and Google with system.web.razor +source and I cannot find
I have searched and cannot find a custom Walker class that will hide the
I have searched everywhere and cannot find a solution to setting css border to
I have searched extensively on this, but cannot find the solution to my problem.
I have searched a lot but cannot find the information i want. I have
I have searched some posts and cannot find what the maximum filesize is under

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.