# Deleting Users in rails console

**URL:** https://meta.discourse.org/t/deleting-users-in-rails-console/141540
**Category:** Support
**Created:** [February 13, 2020, 7:26pm UTC](https://meta.discourse.org/t/deleting-users-in-rails-console/141540 "2020-02-13T19:26:34Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [February 14, 2020, 12:23am UTC](https://meta.discourse.org/t/deleting-users-in-rails-console/141540/2 "2020-02-14T00:23:18Z")

</div>

You’ll want to use the `UserDestroyer` to delete a user properly. Something like this should work:

```plaintext
UserDestroyer.new(Discourse.system_user).destroy(User.find_by_username_or_email("ex@example.com"), delete_posts: false)

```

That will have the system user delete the user with the email `ex@example.com`. You can also provide a username instead of email.

If you want the logs to show who deleted the user, replace `Discourse.system_user` with `User.find_by_username_or_email("admin@example.com")` where `admin@example.com` is the email of a site admin.

---

_[View the full topic](https://meta.discourse.org/t/deleting-users-in-rails-console/141540)._
