Ruby on rails ActionController::UrlGenerationError:没有与之匹配的路由{:action=>;>;index";,:controller=>;>;educations";}
我正在用RSpec在控制器Ruby on rails ActionController::UrlGenerationError:没有与之匹配的路由{:action=>;>;index";,:controller=>;>;educations";},ruby-on-rails,rspec,devise,Ruby On Rails,Rspec,Devise,我正在用RSpec在控制器spec/controllers/educations\u controller\u spec.rb上运行测试 即使在我最基本的get:index测试中,我也得到了错误: ActionController::UrlGenerationError: No route matches {:action=>"index", :controller=>"educations"} 我看过一些关于show/edit/update的帖子,其中需要id,但我认为索引操作不
spec/controllers/educations\u controller\u spec.rb
上运行测试
即使在我最基本的get:index
测试中,我也得到了错误:
ActionController::UrlGenerationError: No route matches {:action=>"index", :controller=>"educations"}
我看过一些关于show/edit/update的帖子,其中需要id,但我认为索引操作不需要id
在spec/controllers/educations\u controller\u 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
您认为这与嵌套在应用程序路由中的教育路由有关吗
我正在使用这个装置。那里会有冲突吗
谢谢你的建议 这与嵌套在应用程序路由中的教育路由有关。如果您rake routes
,您将看到(关于教育):
因此,您的教育路线需要application\u id
您需要:(1)在您的
应用程序教育路径中包含@application
实例,或者(2)取消嵌套路由。控制器是否已经创建,并且上面列出了索引操作?如果运行rake routes
,是否会出现获取/教育
?谢谢@jvillian!这无疑帮助我让考试顺利进行。对于下面的人来说,我遇到的下一个障碍是在create(:user)Great中使用designe:I added=>sign\u登录。请随意投票或接受你认为合适的。我确实投票给了你,但我是超级新人,所以它不会出现。(显然是有记录的?@jvillian
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