2011-08-15 8 views
1

のために私は、ネストされたコントローラをテストし、次のエラーを取得しています。ブラウザの読み込み/チェックリスト/ 1 /アイテムでRSpecのRoutingErrorは、ネストされたコントローラ

1) Checklists::ItemsController index action should render index template 
    Failure/Error: get :index, :checklist_id => checklist.id 
    ActionController::RoutingError: 
     No route matches {:checklist_id=>1, :controller=>"checklists/items"} 

は罰金ロードします。

仕様に何か不足していますか?

経路:

resources :checklists do 
    resources :items, :controller => "Checklists::Items" 
    end 

名前空間フォルダに配置コントローラ(/app/controllers/checklists/items_controller.rb):

class Checklists::ItemsController < ApplicationController 
    respond_to :html, :json 

    def index 
    @checklist_items = @checklist.items 
    respond_with @checklist_items 
    end 
end 

スペック(/スペック/コントローラ/checklists/items_controller_spec.rb):

describe Checklists::ItemsController do 
    let(:user) { Factory :user, :role => 'admin' } 
    let(:checklist) { Factory(:checklist) } 
    let(:checklist_item) { Factory(:checklist_item) } 

    before(:each) do 
    sign_in_to(controller, user) 
    Checklist.stub(:find => checklist) 
    end 

    it "index action should render index template" do 
    get :index, :checklist_id => checklist.id 
    response.should render_template(:index) 
    end 
end 

更新:チェックリストの項目のルート

checklist_items GET /checklists/:checklist_id/items(.:format) {:action=>"index", :controller=>"Checklists::Items"} 
       POST /checklists/:checklist_id/items(.:format) {:action=>"create", :controller=>"Checklists::Items"} 
new_checklist_item GET /checklists/:checklist_id/items/new(.:format) {:action=>"new", :controller=>"Checklists::Items"} 
edit_checklist_item GET /checklists/:checklist_id/items/:id/edit(.:format) {:action=>"edit", :controller=>"Checklists::Items"} 
checklist_item GET /checklists/:checklist_id/items/:id(.:format) {:action=>"show", :controller=>"Checklists::Items"} 
       PUT /checklists/:checklist_id/items/:id(.:format) {:action=>"update", :controller=>"Checklists::Items"} 
       DELETE /checklists/:checklist_id/items/:id(.:format) {:action=>"destroy", :controller=>"Checklists::Items"} 
+0

rakeルートの出力は何ですか? – apneadiving

+0

投稿を更新してルートを追加 – dMix

答えて

2

それは問題を解決するには、ルートにあった判明:

私は

resources :items, :controller => "checklists/items" 

resources :items, :controller => "Checklists::Items" 

を変更それは今働いています

関連する問題