Validating a Model Property is Greater than Another

As you noticed, the only way is to use a custom validator.
The :greater_than option should be an integer. The following code won’t work because both current and next release are available only at instance-level.

class Project < ActiveRecord::Base
  validates_numericality_of :current_release
  validates_numericality_of :next_release, :greater_than => :current_release
end

The purpose of the greater_than option is to validate the value against a static constant or an other class method.

So, don’t mind and go ahead with your custom validator. 🙂

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)