# 특정 사용자의 모든 게시글 복구(삭제 해제)

**URL:** https://meta.discourse.org/t/restore-undelete-all-posts-by-a-user/304643
**Category:** Sysadmins
**Tags:** rails-console
**Created:** [4월 19, 2024, 4:50오후 UTC](https://meta.discourse.org/t/restore-undelete-all-posts-by-a-user/304643 "2024-04-19T16:50:12Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [4월 19, 2024, 4:50오후 UTC](https://meta.discourse.org/t/restore-undelete-all-posts-by-a-user/304643/1 "2024-04-19T16:50:12Z")

</div>

특정 사용자가 삭제한 모든 게시글을 복원/미삭제 처리하려면 다음을 수행할 수 있습니다:

```plaintext
u=User.find_by_username('=username=');
moderator=User.find_by_username('=moderator=');
deleted_posts = Post.with_deleted.where(user_id: u.id).where("deleted_at is not null");
deleted_posts.each do |post|
 PostDestroyer.new(moderator, post).recover
end

```

위 코드를 Rails에 입력해야 한다는 사실이나, Rails에 진입하는 방법을 모른다면 이 작업을 수행하지 않는 것이 좋습니다. 한 번 직접 해본 적이 있으며, 비교적 안전하게 수행할 수 있습니다.

> **Rails에 진입하는 방법**
>
> ```plaintext
> cd /var/discourse
> ./launcher enter app
> rails c
> 
> ```
