# If I want to completely delete a post, I should just hide them?

**URL:** https://meta.discourse.org/t/if-i-want-to-completely-delete-a-post-i-should-just-hide-them/56720
**Category:** Support
**Created:** [01.Февраль.2017 16:30:46 UTC](https://meta.discourse.org/t/if-i-want-to-completely-delete-a-post-i-should-just-hide-them/56720 "2017-02-01T16:30:46Z")
**Posts on this page:** 1
**Showing post:** 14

<div class="post-metadata">

### Author: ![j127](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j127/32/79093_2.png) [@j127](https://meta.discourse.org/u/j127)
#### Post date: [11.Май.2021 06:22:23 UTC](https://meta.discourse.org/t/if-i-want-to-completely-delete-a-post-i-should-just-hide-them/56720/14 "2021-05-11T06:22:23Z")

</div>

Не уверен, что это идеальный вариант, но я использовал этот код, чтобы заменить содержимое постов пользователя в удалённых темах на `"[deleted]"`. Таким образом, существование постов сохранялось, и это казалось безопаснее, чем полное их уничтожение.

```ruby
# сначала сделана резервная копия
deleted_topic_id = 1234
user_id = 5678

t = Topic.unscoped.find(deleted_topic_id)
ps = t.posts.select { |p| p.user_id == user_id }

# `ps.count` для проверки

ps.each do |p|
  p.raw = '[deleted]'
  p.save
end

```

---

_[View the full topic](https://meta.discourse.org/t/if-i-want-to-completely-delete-a-post-i-should-just-hide-them/56720)._
