3

这是'rake routes'的输出

$ rake routes
        new_user_session GET    /users/sign_in(.:format)            devise/sessions#new
            user_session POST   /users/sign_in(.:format)            devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)           devise/sessions#destroy
           user_password POST   /users/password(.:format)           devise/passwords#create
       new_user_password GET    /users/password/new(.:format)       devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format)      devise/passwords#edit
                         PUT    /users/password(.:format)           devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)             devise/registrations#cancel
       user_registration POST   /users(.:format)                    devise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)            devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)               devise/registrations#edit
                         PUT    /users(.:format)                    devise/registrations#update
                         DELETE /users(.:format)                    devise/registrations#destroy
              admin_root        /admin(.:format)                    admin/dashboard#index
         admin_dashboard        /admin/dashboard(.:format)          admin/dashboard#index
              admin_user PUT    /admin/users/:id(.:format)          admin/users#update
batch_action_admin_users POST   /admin/users/batch_action(.:format) admin/users#batch_action
             admin_users GET    /admin/users(.:format)              admin/users#index
                         POST   /admin/users(.:format)              admin/users#create
          new_admin_user GET    /admin/users/new(.:format)          admin/users#new
         edit_admin_user GET    /admin/users/:id/edit(.:format)     admin/users#edit
                         GET    /admin/users/:id(.:format)          admin/users#show
                         PUT    /admin/users/:id(.:format)          admin/users#update
                         DELETE /admin/users/:id(.:format)          admin/users#destroy
                    root        /                                   home#index

这是日志的摘录

Started POST "/admin/users/batch_action" for 127.0.0.1 at 2013-01-18 23:07:07 +0530
Processing by Admin::UsersController#create as HTML

为什么会/admin/users/batch_action被路由到Admin::UsersController#create,当路由显示时 batch_action_admin_users POST /admin/users/batch_action(.:format) admin/users#batch_action

我正在使用 ActiveAdmin,这些是它生成的路由。

4

1 回答 1

1

您似乎正在使用resources路由管理员/用户控制器,因此 POST http 动词默认为create控制器中的操作。

如果您想添加另一个宁静的 POST 控制器操作,请执行以下操作,

scope "admin" do
  resources :users do
    member do
      post 'batch_action'
    end
  end
end

我不知道您的 routes.rb 看起来如何,所以它在您的 routes.rb 文件中可能看起来不同。但它应该看起来相似。

于 2013-01-18T18:03:39.407 回答