Profanity Filter for Rails Application

Nathan Esquenazi wrote:

I am creating an application that allows a user to post messages to a board. I want to be able to filter profanity. For instance if someone types an inappropriate word of 5 characters I want it to read "#?@#@" or whatever. Ideally, I would be able to install a rails plugin or ruby gem and then simply write

Code : - fold - unfold

  --> message_text.hide_profanity! <--

and that would automatically hide all words deemed inappropriate by the filter.

I would also be OK with it being part of the validation, i.e.

--> validates_no_profanity :message <--

which would raise errors should there be any profanity in the value.

Is there any easy rails plugin or ruby gem that does this. This seems like such a common need for an application that reinventing the wheel seems foolish.

Thanks,

-Nathan

I just created a Profanity Filter plugin for Rails during the Community Code Drive at RailsConf 08. It's just a one-liner in your model. You can find it here:

http://github.com/adambair/profanity-filter/tree/master

If you encounter any issues, just log your concern at:

http://adambair.lighthouseapp.com/projects/12000-profanity-filter/tickets

Hopefully someone will find this useful!

Adam Bair wrote:

I just created a Profanity Filter plugin for Rails during the Community Code Drive at RailsConf 08. It's just a one-liner in your model. You can find it here:

http://github.com/adambair/profanity-filter/tree/master

If you encounter any issues, just log your concern at:

Tickets - Fu-fu: The Profanity Filter for Rails - adambair

Hopefully someone will find this useful!

Actually, I just renamed this to Fu-fu: The Profanity Filter for Rails.

http://adambair.lighthouseapp.com/projects/12000-fu-fu/overview

Adam Bair wrote:

Adam Bair wrote:

I just created a Profanity Filter plugin for Rails during the Community Code Drive at RailsConf 08. It's just a one-liner in your model. You can find it here:

Cool... I wrote my own solution to this a while ago. Not as elegant, perhaps.

http://pastie.caboo.se/206695

Matthew Rudy Jacobs wrote:

Cool... I wrote my own solution to this a while ago. Not as elegant, perhaps.

Parked at Loopia

also, my solution is just a view helper... hence we don't destroy our user's data.

it may be the case that you want to censor something in one context (a front page "random comment" perhaps?) but keep the original content in its true form on the proper page.

Matthew Rudy Jacobs wrote:

Matthew Rudy Jacobs wrote:

Cool... I wrote my own solution to this a while ago. Not as elegant, perhaps.

Parked at Loopia

also, my solution is just a view helper... hence we don't destroy our user's data.

it may be the case that you want to censor something in one context (a front page "random comment" perhaps?) but keep the original content in its true form on the proper page.

Yeah, the data modification could be an issue for some folks and will be changing shortly.

I'll be updating the plugin over the next day or so the original text will be left in the database: http://adambair.lighthouseapp.com/projects/12000/tickets/4-provide-an-option-to-make-the-filter-non-destructive

I'll also be working on a new (better) regex for curse detection: http://adambair.lighthouseapp.com/projects/12000/tickets/6-update-filter-to-use-a-more-appropriate-regex

Thanks for the suggestions! Please feel free to create new tickets. :slight_smile:

Matthew Rudy Jacobs wrote:

Matthew Rudy Jacobs wrote:

Cool... I wrote my own solution to this a while ago. Not as elegant, perhaps.

Parked at Loopia

also, my solution is just a view helper... hence we don't destroy our user's data.

it may be the case that you want to censor something in one context (a front page "random comment" perhaps?) but keep the original content in its true form on the proper page.

Fu-fu now has two modes: destructive (profanity_filter!) and non-destructive (profanity_filter). The non-destructive version will leave the original text in the database and only filter when called. The safe method will not modify stored data.