I’m getting a routing error: No route matches [POST] “/students/1” that I can’t figure out. Here are the details.
view code:
<% @students.each do |student| %>
.
.
<td><%= link_to 'Show', student %></td>
<td><%= link_to 'Edit', edit_student_path(student) %></td>
<td><%= link_to 'Select Subjects', select_path(student) %></td> # error occurs here
In my students controller:
def select
.
.
end
routes.rb:
HomeSchool::Application.routes.draw do
resources :notes
resources :assignments
resources :subjects do
resources :assignments, :only => [:create, :index, :new]
end
resources :students
resources :resources
match "students/:id/select" => "students#select", :as => :select
root :to => 'students#index'
end
The output from rake routes is:
GET /students/:id/select(.:format) students/:id#select
notes GET /notes(.:format) notes#index
POST /notes(.:format) notes#create
new_note GET /notes/new(.:format) notes#new
edit_note GET /notes/:id/edit(.:format) notes#edit
note GET /notes/:id(.:format) notes#show
PUT /notes/:id(.:format) notes#update
DELETE /notes/:id(.:format) notes#destroy
assignments GET /assignments(.:format) assignments#index
POST /assignments(.:format) assignments#create
new_assignment GET /assignments/new(.:format) assignments#new
edit_assignment GET /assignments/:id/edit(.:format) assignments#edit
assignment GET /assignments/:id(.:format) assignments#show
PUT /assignments/:id(.:format) assignments#update
DELETE /assignments/:id(.:format) assignments#destroy
subject_assignments GET /subjects/:subject_id/assignments(.:format) assignments#index
POST /subjects/:subject_id/assignments(.:format) assignments#create
new_subject_assignment GET /subjects/:subject_id/assignments/new(.:format) assignments#new
subjects GET /subjects(.:format) subjects#index
POST /subjects(.:format) subjects#create
new_subject GET /subjects/new(.:format) subjects#new
edit_subject GET /subjects/:id/edit(.:format) subjects#edit
subject GET /subjects/:id(.:format) subjects#show
PUT /subjects/:id(.:format) subjects#update
DELETE /subjects/:id(.:format) subjects#destroy
students GET /students(.:format) students#index
POST /students(.:format) students#create
new_student GET /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
resources GET /resources(.:format) resources#index
POST /resources(.:format) resources#create
new_resource GET /resources/new(.:format) resources#new
edit_resource GET /resources/:id/edit(.:format) resources#edit
resource GET /resources/:id(.:format) resources#show
PUT /resources/:id(.:format) resources#update
DELETE /resources/:id(.:format) resources#destroy
select /students/:id/select(.:format) students#select
root / students#index
Any suggestions? I’m having a really hard time grasping exactly how routing in rails is supposed to work and I have yet to find any kind of treatise on it but I’m pretty sure that having no method listed for my select route is at least part of my problem.
Thanks,
Lon
Try removing the
matchin yourroutes.rbfile and change yourstudentsresource to this:Also update your view to call
select_student_path(student).