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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:23:46+00:00 2026-05-29T13:23:46+00:00

My nested resource are associated in the models and the routes.rb: resources :foos do

  • 0

My nested resource are associated in the models and the routes.rb:

resources :foos do
  resources :bars
end

My app is routing ok, but I can’t seem to prove any assertions about my nested routes:

describe BarsController do

it "should have a route to 'show'" do
  assert_generates "/foos/bars/1", 
                   {controller: :bars, action: :show, id: "1"}
end

Here is the error:

Failure/Error: assert_generates "/foos/bars/1",
ActionController::RoutingError:
No route matches {:controller=>"bars", :action=>"show", :id=>"1"}

How do I test these nested 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-05-29T13:23:46+00:00Added an answer on May 29, 2026 at 1:23 pm

    When you run rake routes you should see that your nested routes look something like this:

    foo_bar GET    /foos/:foo_id/bars/:id(.:format)      bars#show
    

    So two parameters are required to match this route: foo_id and id. Since you’re only supplying the id, it’s failing to find a route.

    Also, for testing routes in rspec, you may find it more useful to use the built-in routes_to matcher instead of falling back to assert_*, like this:

    it "routes to the 'show' action" do
      { get: "/foos/123/bars/456" }.
        should route_to controller: "bars",
          action: "show",
          foo_id: "123",
          id: "456"
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a nested resource like so: resources :users resources :posts end and
I have the following nested resources in my routes.rb file. The inner resource specifies
I have a nested resource in my routes.rb like this: map.resources :users, :only =>
I have a nested resource, setup like this: resources :chickens do resources :eggs end
I have the following rails 3 nested resource: resources :books do resources :authors end
So I have a nested resource with resources :albums do resources :elements end I
I have a nested resource defined in routes.db: resources :accounts do resources :transactions do
I have a nested resource: resources :users do resources :cust_uploads end After uploads are
I have a nested resource that looks like this: resources :events resources :attendances post
I have 2 resources, one being a nested resource of another: parent_resource and child_resource

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.