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
# 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:
That’s it!
Did you like this article? Did it save you some time?