Links
Soft Validations
Categories
Soft Validations
Use the soft_validate method to provide 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)
end
end
Call complete? to generate the warnings:
>> e = Employee.new
>> e.complete?
=> false
>> e.warnings.on(:first_name)
=> "shouldn't be blank"
Vitals
| Home | http://softvalidations.rubyforge.org/ |
|---|---|
| Repository | svn://rubyforge.org/var/svn/softvalidations |
| License | Rails' (MIT) |
| Tags |
|
| Rating | (4 votes) |
| Owner | Julia West |
| Created | 18 January 2008 |

