Soft Validations for Rails

This plugin provides an additional Errors object, referred to as warnings, to ActiveRecord objects. The warnings object is not tied in to a model's life cycle. Thus, an ActiveRecord object can be saved while still having messages in its warnings. This might be useful for sites that would want to keep track of recommended fields for users to complete, or sites with large amounts of erroneous imported data which might benefit from suspending some validations for a little while.


script/plugin install svn://


Use SoftValidations::Validation#soft_validation to add a descriptive declaration of an ActiveRecord object's desired state in order to be considered complete. The methods or block passed to soft_validate should add a message to the class's warning collection.

  class Employee < ActiveRecord::Base
    soft_validate :should_have_first_name
    def should_have_first_name
      warnings.add(:first_name, "shouldn't be blank") unless attribute_present?(:first_name)

To generate warnings, you should first call complete?

  >> employee =
  >> employee.complete? 
  => false
  >> employee.warnings.on(:first_name) 
  => "shouldn't be blank"

More Info