我添加了一个新的控制器动作并添加了对应的路由
def students
@students = Swimming::Student.all
render :json => @students
end
namespace :swimming do
resources :classschedules do
get 'students', :action => 'students', :as => :students ,:on => :collection
end
end
但是当我访问这个页面时
http://localhost:3000/swimming/classschedules/students
我收到了这个错误
ActiveRecord::RecordNotFound in Swimming::ClassschedulesController#show
Couldn't find Swimming::Classschedule with id=students
看起来rails试图加载另一条路线
GET /swimming/classschedules/:id(.:format) swimming/classschedules#show
我正在附加所有相关路线
swimming_classschedules GET /swimming/classschedules(.:format) swimming/classschedules#index
POST /swimming/classschedules(.:format) swimming/classschedules#create
new_swimming_classschedule GET /swimming/classschedules/new(.:format) swimming/classschedules#new
edit_swimming_classschedule GET /swimming/classschedules/:id/edit(.:format) swimming/classschedules#edit
swimming_classschedule GET /swimming/classschedules/:id(.:format) swimming/classschedules#show
PUT /swimming/classschedules/:id(.:format) swimming/classschedules#update
DELETE /swimming/classschedules/:id(.:format) swimming/classschedules#destroy
date_swimming_classschedules GET /swimming/classschedules/date/:date(.:format) swimming/classschedules#date
students_swimming_classschedules GET /swimming/classschedules/students(.:format) swimming/classschedules#students
editnote_swimming_classschedules POST /swimming/classschedules/editnote/:date(.:format) swimming/classschedules#editnote
GET /swimming/classschedules(.:format) swimming/classschedules#index
POST /swimming/classschedules(.:format) swimming/classschedules#create
GET /swimming/classschedules/new(.:format) swimming/classschedules#new
GET /swimming/classschedules/:id/edit(.:format) swimming/classschedules#edit
GET /swimming/classschedules/:id(.:format) swimming/classschedules#show
PUT /swimming/classschedules/:id(.:format) swimming/classschedules#update
DELETE /swimming/classschedules/:id(.:format) swimming/classschedules#destroy
如何解决这个问题?
更新*已修复*
问题是因为我有两个块
namespace :swimming do
resources :classschedules do
end
end
在路线.rb