I have a application whereby a user can destroy other users attached to the same account.
I use Devise for authentication and want to be able to allow a user to destroy other users. I have this bit working but I’m struggling to prevent devise from logging me out even though I’m deleting another user.
I have created my own registrations_controller:
class RegistrationsController < Devise::RegistrationsController
def new
super
end
def create
super
end
def edit
...
super
end
def update
...
end
def destroy
resource.destroy
set_flash_message :notice, :destroyed
redirect_to :root
end
end
And the link that destroys each one of my users looks like this:
<%= link_to "Yes", registration_path(@user), :remote => true, :method => :delete, :class => "button" %>
However, each time I click this link it logs me out even though it is another user I am deleting.
Any ideas?
For anyone else having this problem I solved this via this post. Basically devise can’t delete any other user apart from the current one. You need to add a destroy action to destroy users to your other controller that is displaying the current view:
Destroying users as an admin in Devise