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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:54:08+00:00 2026-06-06T22:54:08+00:00

I have 2 resources, one being a nested resource of another: parent_resource and child_resource

  • 0

I have 2 resources, one being a nested resource of another:

parent_resource and child_resource.

This gives me the following routes:

somesite.com/parent_resources/14
somesite.com/parent_resources/14/child_resources/1

However there is only ever going to be a single child_resource for each parent_resource, so to someone using the site this is very confusing. I would like the child_resource paths to look like this:

somesite.com/parent_resource/14/child_resource
somesite.com/parent_resource/14/child_resource/edit
etc

What is the correct way to do this?

My routes.rb

resources :parent_resources do

   resource :child_resource do
   end

end 

From the rails guide to routing:

A singular resourceful route generates these helpers:

new_geocoder_path returns /geocoder/new
edit_geocoder_path returns /geocoder/edit
geocoder_path returns /geocoder

But what about show?

My routes generated by rake routes:

parent_resource_child_resource      POST   /parent_resources/:parent_resource_id/child_resource(.:format)                 child_resources#create


new_parent_resource_child_resource  GET    /parent_resources/:parent_resource_id/child_resource/new(.:format)             child_resources#new

edit_parent_resource_child_resource GET    /parent_resources/:parent_resource_id/child_resource/edit(.:format)            child_resources#edit

                                    GET    /parent_resources/:parent_resource_id/child_resource(.:format)                 child_resources#show

                                    PUT    /parent_resources/:parent_resource_id/child_resource(.:format)                 child_resources#update

                                    DELETE /parent_resources/:parent_resource_id/child_resource(.:format)                 child_resources#destroy
  • 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-06T22:54:09+00:00Added an answer on June 6, 2026 at 10:54 pm

    In your routes, define the child resource using the singular resource method:

    resources :parent_resources do
      resource :child_resource
    end
    

    By convention, the controller for the child will still be ChildResourcesController, plural.

    Rails has a pretty good guide to routing. See the section on singular resources.

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

Sidebar

Related Questions

In my routes I have: resources :accounts This produces: accounts GET /accounts(.:format) accounts#index POST
I have some static resources (images and HTML files) that will be localized. One
Consider that I have 1 resource and 2 urls (let's say new one and
In routes.rb i have: resources :themes do resources :messages end In messages_controller_test.rb i have:
In my routes I currently have resources :users and so I get the routes
in my routes.rb I have: resources :boards do resources :items end now in boards#show
Googling this does little good, as you can imagine. Does anyone have resources that
Say I have the following routes that are constrained to specific subdomains: App::Application.routes.draw do
I have been all over this one, and I am just plumb stuck. I
I have WPF application with one main window . In this window there are

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.