Alex Rivera | Logout

How to "soft delete" user with Devise

Asked 2011-02-28T10:13:14.417
68

I currently use Devise for user registration/authentication in a Rails project. When a user wants to cancel their account, the user object is destroyed, which leaves my application in an undesired state.

What is the easiest way to implement a "soft delete", i.e. only removing personal data and marking the user as deleted? I still want to keep all record associations.

I assume I will have to first introduce a new "deleted" column for users. But then I am stuck with this default code in the user's profile view:

<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>

Where can I find the :delete method? How should I overwrite the default Devise methods?

Edit
Report

1 Answer

96

Adding onto hakunin's answer:

To prevent "soft deleted" users from signing in, override active_for_authentication? on your User model:

def active_for_authentication?
  super && !deleted_at
end
answered 2011-11-12T22:13:27.223

Your Answer