Class: ActiveRecord::Errors

Inherits:
Object
  • Object
show all
Defined in:
lib/validations.rb

Instance Method Summary collapse

Instance Method Details

#add_on_null(attributes, msg = ) ⇒ Object

Add an error message to each of the attributes in attributes that is null



8
9
10
11
12
13
# File 'lib/validations.rb', line 8

def add_on_null(attributes, msg = @@default_error_messages[:null])
  for attr in [attributes].flatten
    value = @base.respond_to?(attr.to_s) ? @base.send(attr.to_s) : @base[attr.to_s]
    add(attr, msg) if value.nil? 
  end
end