【发布时间】:2017-06-19 18:27:20
【问题描述】:
我正在使用 RSpec 在控制器 spec/controllers/educations_controller_spec.rb 上运行测试。
即使在我对 get :index 的最基本测试中,我也遇到了错误:
ActionController::UrlGenerationError: No route matches {:action=>"index", :controller=>"educations"}
我看过有关显示/编辑/更新需要 id 的帖子,但我认为索引操作不需要 id。
在 spec/controllers/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
您认为这与嵌套在应用程序路由中的教育路由有关吗?
我正在使用设计。那里会不会有冲突?
感谢您的任何建议!
【问题讨论】:
-
控制器是否已经制作完毕,并且上面列出了索引操作?
-
如果您运行
rake routes,是否会出现GET /educations?
标签: ruby-on-rails rspec devise