2

新しいコントローラーアクションを追加し、対応するルートを追加しました

  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

レールが別のルートを読み込もうとしているようです

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

この問題を解決するにはどうすればよいですか?

更新*修正されました*

2つのブロックがあったための問題

  namespace :swimming do 
    resources :classschedules do

     end 

   end

routes.rb で

4

1 に答える 1