An easy way to find and censor profanity (bad words) is to use the gem swearjar

# terminal
bundle add swearjar
# app/models/message.rb
  def moderated_body
    Swearjar.default.censor(body)
  end
# app/views/messages/_message.html.erb
-<%= message.body %>
+<%= message.moderated_body %>

Result:

swearjar-profanity-filter

That’s it!