Module: ActiveRecord::Validations::ClassMethods
- Defined in:
- lib/validations.rb
Instance Method Summary collapse
-
#validates_nullability_of(*attr_names) ⇒ Object
NOTE: template for this method borrowed from validates_presence_of method in Rails.
Instance Method Details
#validates_nullability_of(*attr_names) ⇒ Object
NOTE: template for this method borrowed from validates_presence_of method in Rails
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/validations.rb', line 22 def validates_nullability_of(*attr_names) configuration = { :message => ActiveRecord::Errors.[:null], :on => :save } configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash) # can't use validates_each here, because it cannot cope with nonexistent attributes, # while errors.add_on_empty can attr_names.each do |attr_name| send(validation_method(configuration[:on])) do |record| unless configuration[:if] and not evaluate_condition(configuration[:if], record) record.errors.add_on_null(attr_name,configuration[:message]) end end end end |