---
title: "Use SwearJar to moderate and censor bad words. **** you!"
author: "Yaroslav Shmarov"
date: "2022-08-30"
canonical_url: "https://blog.superails.com/swearjar-profanity-filter"
markdown_url: "https://blog.superails.com/swearjar-profanity-filter.md"
description: "An easy way to find and censor profanity (bad words) is to use the gem swearjar{:target=\"blank\"} Result: That's it!"
tags: ["ruby-on-rails","profanity","moderation"]
license: "GNU AGPL v3. Credit Yaroslav Shmarov and link the canonical URL."
---

# Use SwearJar to moderate and censor bad words. **** you!

An easy way to find and censor profanity (bad words) is to use the gem [swearjar](https://github.com/joshbuddy/swearjar){:target="blank"}

```shell
# terminal
bundle add swearjar
```

```ruby
# app/models/message.rb
  def moderated_body
    Swearjar.default.censor(body)
  end
```

```diff
# app/views/messages/_message.html.erb
-<%= message.body %>
+<%= message.moderated_body %>
```

Result:

![swearjar-profanity-filter](https://blog.superails.com/assets/images/swearjar-profanity-filter.png)

That's it!
