简体   繁体   中英

Devise/ Delete user Error

I am creating a form for an admin to go in and list, edit and delete users. I have tried many different variations for deleting a user and nothing works. I am wondering if it is because I need to use devise_for :users and resources :users in my routes.rb. This is because I have uploads/attachments linked to users. But here is my link

<%= link_to 'Delete',user, :method => 'delete',  :confirm => 'Are you sure?' %>

And my routes.rb

# devise_for :users
devise_for :users do
  get "/users/sign_out" => "devise/sessions#destroy", :as => :destroy_user_session
end
resources :users  do
  resources :attachments
end

The error I am receiving is The action 'destroy' could not be found for UsersController.

But my users controller has

def destroy
  @user = User.find(params[:id]).destroy
  redirect_to admin_index, :flash => { :success => 'User was successfully deleted.' }
end

If you are not using ajax for the requests, the problem is taht you ar using a link_to

In order to send the :method => 'delete' you have to use a button, jus like this:

<%= button_to 'Delete', user, :method => 'delete',  :confirm => 'Are you sure?' %>

Because destructive action must be performed with a form submission:

http://www.w3.org/2001/tag/doc/whenToUseGet.html#checklist

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM