I am trying to use Devise to delete users. I have a list of users, each of whom has his own e-mail and a delete link next to them, only for me, the administrator. I want to be able to simply click the delete link to delete the user permanently. The following code removes me, admin!
<%= link_to "delete", user_registration_path, :method => :delete, :confirm => "You sure?" %>
I think you need to pass the identifier of the user you want to delete to some destroy_user method:
@user.find(params[:id]).destroy_user
But how do you do this when you need to send a DELETE request to user_registration_path?
------ EDIT --------
OK, I added this method to my user controller:
def destroy User.find(params[:id]).destroy flash[:success] = "User destroyed." redirect_to users_path end
So, I need to tell the user controller to call the destroy method when it receives a DELETE request. How do you do this in routes.rb? I currently have:
match '/users/:id', :to => 'users#show', :as => :user match '/all_users', :to => 'users#index', :as => :all_users
I need something like:
match 'delete_user', :to => 'users#destroy', :as => :destroy_user, :method => :delete
but it does not work. And what should follow the link ?:
<%= link_to "delete", destroy_user, :method => :delete, :confirm => "You sure?" %>
In other words, what should you put in the route.rb file to distinguish between different types of requests (GET, DELETE, etc.) with the same URL?