Skip to content

Instantly share code, notes, and snippets.

@courtsimas
Created July 27, 2011 22:16
Show Gist options
  • Save courtsimas/1110495 to your computer and use it in GitHub Desktop.
Save courtsimas/1110495 to your computer and use it in GitHub Desktop.
////in questions#create action
if filter_profanity( @question.body, I18n.t(:bad_words).split( /, */ ) ).present?
redirect_to @question, :alert => I18n.t(:bad_words_warning) and return
end
///in the application controller
def filter_profanity( check_str = "", prohibited_words = [] )
return check_str.downcase.gsub!(/[^a-z]/, " ").split(" ").uniq.map { |w| w if prohibited_words.include?( w ) }.compact!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment