Rails路由错误:没有路由匹配[POST]“/ students / 1”

时间:2012-08-13 04:28:34

标签: ruby-on-rails ruby-on-rails-3

我收到路由错误:没有路由匹配[POST]“/ students / 1”我无法弄清楚。以下是详细信息。

查看代码:

<% @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

在我的学生管理员中:

def select
  .
  .
end

routes.rb中:     HomeSchool :: Application.routes.draw做

  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

佣金路线的输出是:

                       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

有什么建议吗?我真的很难理解轨道中的路由应该如何工作,我还没有找到任何类型的论文,但我很确定没有为我的选择路由列出的方法至少是我的问题。

谢谢,

经度

2 个答案:

答案 0 :(得分:1)

尝试删除match文件中的routes.rb,并将students资源更改为:

resources :students do
  member do
    get 'select'
  end
end

同时更新您的观看次数以致电select_student_path(student)

答案 1 :(得分:0)

发生这种情况是由于您的route.rb文件。在“ / students / new”中没有post方法的回调

更正此问题。 转到routes.rb,并在结尾之前添加Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

并检查post 'students/new' to: 'students#new'。您将在那里找到帖子的路由路径。