views:

24

answers:

1

I have a nested resource, setup like this:

 resources :chickens do
      resources :eggs
 end

The views for the EggsController are under views/eggs, but:

describe "eggs/index.html.erb" do

gives a "No route matches {:action => "create", :controller => "eggs"} error on calling render. How do I get RSpec to find the correct (nested) route for view specs?

As a side note, is there any way to specify a nested resource to the Rails 3 controller scaffold generator?

+1  A: 

The test looks ok to me...

By any chance do you have a form on your eggs/index.html.erb for creating new eggs that might not yet be wired up correctly? It seems it may be trying to render the index view but failing because the view is trying build a route that doesn't exist? You'd want to make sure that the form is using the correct nested resource route. Does the view render when you load it up in the browser?

njorden
You were right that the issue is on the add new link on the view (removing removes the failure), but the path (new_chicken_egg_path) works in the browser. I am, by the way, doing an assign(:chicken, @chicken) in the spec, not that the path is _explicitly_ taking it as a parameter. params[:chicken_id] = @chicken is also being set. I happen to be using factory_girl for these.
Christopher Foy
Ah. I am using a form_for([@chicken, @egg]), so I'll double-check that that's working.
Christopher Foy
All good now. Started getting a no route for the new, but just added @chicken as a param to the new_chicken_egg_path method. Thanks!
Christopher Foy