mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +02:00
Refactor domain contact uniq validation method
This commit is contained in:
parent
cd7151b463
commit
dd38b7dfe6
2 changed files with 20 additions and 24 deletions
|
@ -7,7 +7,8 @@ class UniquenessMultiValidator < ActiveModel::EachValidator
|
|||
existing = list.select { |y| x.send(options[:attribute]) == y.send(options[:attribute]) }
|
||||
next unless existing.length > 1
|
||||
validated << x.send(options[:attribute])
|
||||
record.errors.add(attribute, :invalid) if record.errors[attribute].blank?
|
||||
association = options[:association] || attribute
|
||||
record.errors.add(association, :invalid) if record.errors[association].blank?
|
||||
x.errors.add(options[:attribute], :taken)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue