0

我刚刚从 padrino/sinatra 切换到 rails,所以路由的东西让我很困惑。

我已经定义,

  namespace :admin do
    resources :teachers, :students, :lessons
  end

在我的 routes.rb 文件中,当我运行 rake routes 命令时,它给了我,

    admin_teachers GET    /admin/teachers(.:format)          admin/teachers#index
                   POST   /admin/teachers(.:format)          admin/teachers#create
 new_admin_teacher GET    /admin/teachers/new(.:format)      admin/teachers#new
edit_admin_teacher GET    /admin/teachers/:id/edit(.:format) admin/teachers#edit
     admin_teacher GET    /admin/teachers/:id(.:format)      admin/teachers#show
                   PUT    /admin/teachers/:id(.:format)      admin/teachers#update
                   DELETE /admin/teachers/:id(.:format)      admin/teachers#destroy
    admin_students GET    /admin/students(.:format)          admin/students#index
                   POST   /admin/students(.:format)          admin/students#create
 new_admin_student GET    /admin/students/new(.:format)      admin/students#new
edit_admin_student GET    /admin/students/:id/edit(.:format) admin/students#edit
     admin_student GET    /admin/students/:id(.:format)      admin/students#show
                   PUT    /admin/students/:id(.:format)      admin/students#update
                   DELETE /admin/students/:id(.:format)      admin/students#destroy
     admin_lessons GET    /admin/lessons(.:format)           admin/lessons#index
                   POST   /admin/lessons(.:format)           admin/lessons#create
  new_admin_lesson GET    /admin/lessons/new(.:format)       admin/lessons#new
 edit_admin_lesson GET    /admin/lessons/:id/edit(.:format)  admin/lessons#edit
      admin_lesson GET    /admin/lessons/:id(.:format)       admin/lessons#show
                   PUT    /admin/lessons/:id(.:format)       admin/lessons#update
                   DELETE /admin/lessons/:id(.:format)       admin/lessons#destroy

问题是,我不知道如何响应管理员/学生#update 的请求?我知道如何回应 admin#teachers,在我的管理控制器中我创建了一个教师功能。但是如何回应 admin/teachers/index 呢?或者也许在哪里回应?在哪个文件中?在哪个函数或类中?

4

1 回答 1

1

对于admin/students#updateRails 将在此处查找操作:

class Admin::StudentsController < ApplicationController
  def update
    # update here
  end
end

您可以使用以下命令生成此文件:

rails generate controller admin/students update

这将写入:

app/controllers/admin/students_controller.rb
于 2012-06-24T23:07:51.993 回答