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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:59:36+00:00 2026-06-05T12:59:36+00:00

I’m using inherited_resources to DRY my controllers, but can’t figure out how to make

  • 0

I’m using inherited_resources to DRY my controllers, but can’t figure out how to make a particular controller behave correctly. In my model, User has_one Person. I want it to be optionally nested, behave as a singleton when nested, and as a non-singleton when not nested. In other words, I want to be able to list all known people (/people), get person #5 (/person/5), and get user 10’s only person (/user/10/person). The following in routes.rb:

resources :users
  resource :person
end
resources :people

…sets up the routes as I expect:

         user_person POST   /users/:user_id/person(.:format)                people#create
     new_user_person GET    /users/:user_id/person/new(.:format)            people#new
    edit_user_person GET    /users/:user_id/person/edit(.:format)           people#edit
                     GET    /users/:user_id/person(.:format)                people#show
                     PUT    /users/:user_id/person(.:format)                people#update
                     DELETE /users/:user_id/person(.:format)                people#destroy

              people GET    /people(.:format)                               people#index
                     POST   /people(.:format)                               people#create
          new_person GET    /people/new(.:format)                           people#new
         edit_person GET    /people/:id/edit(.:format)                      people#edit
              person GET    /people/:id(.:format)                           people#show
                     PUT    /people/:id(.:format)                           people#update
                     DELETE /people/:id(.:format)                           people#destroy

… so great. Now, if in the PeopleController, I use:

belongs_to :user, :optional => true

… then the non-nested /people urls work, but the nested /users/:user_id/person urls don’t: undefined method 'people' If, instead, in the PeopleController, I use:

belongs_to :user, :optional => true, :singleton => true

… then the nested /users/:user_id/person urls work, but the non-nested /people urls don’t because it is being treated as a singleton, even when non-nested: undefined method 'person'

Summary: Is there a way to make inherited_resources handle a resource as a singleton when accessed via a nested route, but as a non-singleton when accessed via a not nested route?

  • 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-05T12:59:37+00:00Added an answer on June 5, 2026 at 12:59 pm

    In case anyone is trying to do something similar, I ended up just abandoning inherited_resources. I’m finding I’m happier with less “magic” going on in my controllers.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am using JSon response to parse title,date content and thumbnail images and place
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a French site that I want to parse, but am running into

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.