validates_blacklist
Validation of Rails models against a database, supporting scoped validation.
Install
Add the following to config/environment.rb
config.gem "bartzon-validates_blacklist", :lib => "validates_blacklist"
And run
rake gems:install
After these steps, generate a migration with:
script/generate blacklists
Usage
Add the follow to each model you want to have validated:
class User < ActiveRecord::Base
validates_blacklist
:fields => [:name] # required, specify the fields to validate
:message => "" # optional, defaults to "is not allowed"
:scope => nil # optional, set this to for instance a class name to allow blacklist validation per class
end
Adding a blacklisted value is as easy as:
User.add_to_blacklist('value')
Per default the scope will be inherited from the options specified in the call to validates_blacklist. This can be changed by doing:
User.add_to_blacklist('value', :scope => 'Foo)