9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/armada/validations.rb', line 9
def validate_each(record, attribute, value)
relation = record.class.where(attribute => value)
Array.wrap(options[:scope]).each do |scope_attribute|
relation = relation.where(scope_attribute => record.attributes[scope_attribute])
end
relation = relation.where(:id => {"!=" => record.id}) if record.persisted?
return if relation.count == 0
record.errors.add(attribute, :taken, :default => options[:message], :value => value)
end
|