我经常在嵌套资源上使用浅层路由,所以以为我错过了一些简单的东西,但不明白为什么我会收到路由错误。students#show
我有一所学校,有两个嵌套资源:课程和学生。所有操作都适用于课程。:index、:new 和 :create 操作适用于学生。
为什么我会收到路由错误,而不是如中所示/students/3
被路由到?students#show
rake routes
例外/students/3
:
Routing Error
No route matches {:controller=>"students"}
Try running rake routes for more information on available routes.
以下是相关位...
耙路线输出:
...
school_students GET /schools/:school_id/students(.:format) students#index
POST /schools/:school_id/students(.:format) students#create
new_school_student GET /schools/:school_id/students/new(.:format) students#new
edit_student GET /students/:id/edit(.:format) students#edit
student GET /students/:id(.:format) students#show
PUT /students/:id(.:format) students#update
DELETE /students/:id(.:format) students#destroy
approve_course GET /courses/:id/approve(.:format) courses#approve
publish_course GET /courses/:id/publish(.:format) courses#publish
school_courses GET /schools/:school_id/courses(.:format) courses#index
POST /schools/:school_id/courses(.:format) courses#create
new_school_course GET /schools/:school_id/courses/new(.:format) courses#new
edit_course GET /courses/:id/edit(.:format) courses#edit
course GET /courses/:id(.:format) courses#show
PUT /courses/:id(.:format) courses#update
DELETE /courses/:id(.:format) courses#destroy
schools GET /schools(.:format) schools#index
POST /schools(.:format) schools#create
new_school GET /schools/new(.:format) schools#new
edit_school GET /schools/:id/edit(.:format) schools#edit
school GET /schools/:id(.:format) schools#show
PUT /schools/:id(.:format) schools#update
DELETE /schools/:id(.:format) schools#destroy
...
路线.rb
Lms::Application.routes.draw do
...
resources :schools, :shallow => true do
resources :students
resources :courses do # Courses still work if I remove this block.
member do
get 'approve'
get 'publish'
end
end
end
...
控制器和视图
我检查了,但由于这是一个路由异常,我认为没有达到此代码。如果你告诉我,我可以添加它们。