more validations

I wrote up a validates_condition_between validations class method the other day. It basically validates that the values of two attributes matches the condition supplied. Only one condition can be used at a time. I searched around for something like this but couldn’t find anything so I wrote it.

Usage:

1
2
3
4
5
6
7


   class Person < ActiveRecord::Base
     validates_condition_between :start_time, :end_time, :condition=>:greater_than
     validates_condition_between :credit, :max_credit, :condition=>:less_than_or_equal_to, :allow_blank => true
     validates_condition_between :key, :keys, :condition=>:inclusion, :allow_nil => true
   end  

I’ve stuck it in the following plugin (just the one validation for now):

1
2

script/plugin install svn://rubyforge.org/var/svn/sidirodromos/plugins/more_validations

Back to articles