# Replace a string in all posts

**URL:** https://meta.discourse.org/t/replace-a-string-in-all-posts/48729
**Category:** Self-Hosting
**Tags:** how-to
**Created:** [August 17, 2016, 10:23am UTC](https://meta.discourse.org/t/replace-a-string-in-all-posts/48729 "2016-08-17T10:23:49Z")
**Posts on this page:** 1
**Showing post:** 166

<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: [January 17, 2023, 7:18pm UTC](https://meta.discourse.org/t/replace-a-string-in-all-posts/48729/166 "2023-01-17T19:18:55Z")

</div>

```plaintext
Topics.where(category_id: 123).each do |t|
  posts.where(topic_id: t).each do |p|
    p.raw.gsub!("replaceme","/")
    p.save
  end
end

```

> [@MiG](#):
>
> Just type in “rails” and then copy the code in there?

```plaintext
./launcher enter app
rails c
# paste in the stuff

```

You might make a backup first.

---

_[View the full topic](https://meta.discourse.org/t/replace-a-string-in-all-posts/48729)._
