0

我剛從padrino/sinatra切換到rails,所以路由的東西讓我感到困惑。Rails 3在控制器內部的路由

我已經定義,

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 

的問題是,我無法弄清楚如何響應管理員/學生的請求#更新?我知道如何回覆管理員#教師,在我的管理員控制器中,我創建了一個教師功能。但如何迴應管理員/教師/索引?或者,也許在哪裏迴應?在哪個文件中?在哪個功能或類中?

回答

1

admin/students#update Rails會查找這裏的行動:

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

您可以生成這個文件:

rails generate controller admin/students update 

這將寫入:

app/controllers/admin/students_controller.rb 
+0

有一臺發電機爲了這?我應該在哪裏把它放在一個新文件中? – gkaykck