3

Here is the output of '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

And here is an excerpt from the logs

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

Why is /admin/users/batch_action getting routed to Admin::UsersController#create, when the routes shows batch_action_admin_users POST /admin/users/batch_action(.:format) admin/users#batch_action

I am using ActiveAdmin and these are the routes that it generates.

1
  • 1
    Solved: Turns out that I was overriding a member action for a custom create method instead of a collection action in the ActiveAdmin controller. This was causing /admin/user/batch_action to be interpreted as a POST to /admin/users/:id where :id was batch_action Commented Jan 18, 2013 at 18:48

1 Answer 1

1

It seems like you are using resources for routing admin/users controller, so POST http verb is defaulted to create action in the controller.

If you would like to add another restful POST controller action, do something like this,

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

I don't know how your routes.rb looks like, so it might look different in your routes.rb file. But it should look similar.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, your answer finally led me to what I was doing wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.