Antivirus
Antivirus provides a validator which filter profane words for Rails application.
Installation
Add this line to your application's Gemfile:
gem 'antivirus'
And then execute:
$ bundle
Usage
Define profane words as array in config/locales/*.yml
with antivirus.profane_words
key.
antivirus.message
key is an error message when value includes profane words.
en:
antivirus:
message: includes profane words.
profane_words:
- foo
- bar
- baz
For example, Post model exists like this:
class Post < ActiveRecord::Base
validates :content, profanity_filter: true
end
In this case, post
can't include profane words.
post = Post.create(content: 'foo')
post.valid?
#=> false
post.errors.full_messages
#=> ["Content includes profane words."]
Contributing
- Fork it ( https://github.com/kami-zh/antivirus/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request