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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:56:12+00:00 2026-05-15T18:56:12+00:00

I am trying to create nested resources where the sub-resource doesn’t have an existence

  • 0

I am trying to create nested resources where the sub-resource doesn’t have an existence of its own. e.g., an Address resource which is linked to a Person.

My route declaration looks like so:

map.resources :persons,
:has_many => :addresses

This gives me the following routes:

             person_addresses GET    /persons/:person_id/addresses                  {:controller=>"addresses", :action=>"index"}
   formatted_person_addresses GET    /persons/:person_id/addresses.:format          {:controller=>"addresses", :action=>"index"}
                              POST   /persons/:person_id/addresses                  {:controller=>"addresses", :action=>"create"}
                              POST   /persons/:person_id/addresses.:format          {:controller=>"addresses", :action=>"create"}
           new_person_address GET    /persons/:person_id/addresses/new              {:controller=>"addresses", :action=>"new"}
 formatted_new_person_address GET    /persons/:person_id/addresses/new.:format      {:controller=>"addresses", :action=>"new"}
          edit_person_address GET    /persons/:person_id/addresses/:id/edit         {:controller=>"addresses", :action=>"edit"}
formatted_edit_person_address GET    /persons/:person_id/addresses/:id/edit.:format {:controller=>"addresses", :action=>"edit"}
               person_address GET    /persons/:person_id/addresses/:id              {:controller=>"addresses", :action=>"show"}
     formatted_person_address GET    /persons/:person_id/addresses/:id.:format      {:controller=>"addresses", :action=>"show"}
                              PUT    /persons/:person_id/addresses/:id              {:controller=>"addresses", :action=>"update"}
                              PUT    /persons/:person_id/addresses/:id.:format      {:controller=>"addresses", :action=>"update"}
                              DELETE /persons/:person_id/addresses/:id              {:controller=>"addresses", :action=>"destroy"}
                              DELETE /persons/:person_id/addresses/:id.:format      {:controller=>"addresses", :action=>"destroy"}

Now I want to make sure that a person’s addresses are read-only, i.e., I only want the show and index actions for an address.

I tried this:

  map.resources :persons,
  :has_many => :addresses,
  :collection => { :addresses => [ :show, :index ] }

and got this error:

(in /home/rmk/app)
rake aborted!
Invalid HTTP method specified in route conditions: {:method=>:show}

(See full trace by running task with --trace)

Is there any way I can achieve this?

EDIT:
My main problem was that I was not using the code block properly (I wanted to use has_one etc. as much as possible). So my persons routes look like this (somewhat contrived example):

map.resources :persons, :has_one => :ssn, :except => [:new, :edit] do |person|
 person.resources :addresses, :only => [:index, :show]
end
  • 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-15T18:56:13+00:00Added an answer on May 15, 2026 at 6:56 pm

    Is this what you’re trying to do?

    map.resources :persons do |person|
      person.resources :addresses, :only => [:index, :show]
    end
    

    This creates addresses as a nested resource of persons, but only makes the index and show views available.

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

Sidebar

Related Questions

I'm trying to create a nested resource with a url scheme along the lines
I'm trying to create a nested list in Flex which will dynamically resize to
I am trying to create some nested divs where the middle one should have
I’m trying to create an instance of: java.awt.geom.Point2D.Double in ColdFusion. Point2D.Double is a nested
I am trying to create nested array's dynamically from a string that has been
I am trying to create an Enhanced Grid with nested sorting functionality in Dojo
I'm trying to create a mega menu using nested <ul> within a <li> .
Having some trouble with some nested resources routing. What I'm trying to do is
I'm using the awesome_nested_set plugin in my Rails project. I'm trying to create nested
I'm trying to create a nested form but I'm missing something as keep getting

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.