2017-06-19 89 views
0

我运行测试,控制器spec/controllers/educations_controller_spec.rb上,使用RSpec。的ActionController :: UrlGenerationError:没有路由匹配{:动作=> “指数”:控制器=> “教育”}

即使在我最基础的测试获得:index我收到错误:

ActionController::UrlGenerationError: No route matches {:action=>"index", :controller=>"educations"} 

我所看到的关于显示/编辑/更新帖子在需要的ID,但我不认为一个id应该是索引操作所必需的。

在投机/控制器/ educations_controller_spec.rb:

require 'rails_helper' 

RSpec.describe EducationsController, type: :controller do 
    describe 'GET #index' do 
    it "renders the :index template" do 
     get :index 
     expect(response).to render_template :index 
    end 
    end 
end 

我的路线文件中包含该索引操作:

resources :applications, only: [:index, :new, :show, :create, :edit, :update] do 
    resources :educations, only: [:index, :new, :create, :edit, :update] 
    resources :montessori_trainings, only: [:index, :new, :create, :edit, :update] 
    resources :work_experiences, only: [:index, :new, :create, :edit, :update] 
    resources :references, only: [:index, :new, :create, :edit, :update] 
    resources :documents, only: [:index, :new, :create, :edit, :update] 
end 

你认为它是与被嵌套在教育路线应用程序路线?

我使用的设计。那里会有冲突吗?

感谢您的任何和所有的建议!

+0

是已经制定的控制器,并列出了一个索引操作? –

+0

如果您运行'rake routes',会出现'GET/educations'? – tegon

回答

1

正是有嵌套在应用程序内航线的教育路线做。如果您rake routes,你会看到(用于的教育):

 application_educations GET /applications/:application_id/educations(.:format)     educations#index 
          POST /applications/:application_id/educations(.:format)     educations#create 
    new_application_education GET /applications/:application_id/educations/new(.:format)    educations#new 
    edit_application_education GET /applications/:application_id/educations/:id/edit(.:format)   educations#edit 
     application_education PATCH /applications/:application_id/educations/:id(.:format)    educations#update 
          PUT /applications/:application_id/educations/:id(.:format)    educations#update 

所以,你的教育路线期待application_id

您需要:(1)在您的application_educations_path中包含@application实例或(2)取消嵌套路由。

+0

谢谢@jvillian!这绝对有助于我的测试工作。对于任何接下来的人来说,我碰到的下一个障碍就是用Devise登录:我在我的educations_controller_spec.rb中添加了=> sign_in create(:user)<=,它阻止了我被重定向到一个登录页面,我对索引 – jamieRonin

+0

太好了。随时欢迎或接受,因为你认为合适。 – jvillian

+0

我确实鼓励了你,但我是超级新人,所以没有表现出来。 (显然它被记录?)@jvillian – jamieRonin

相关问题