mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 17:28:18 +02:00
Refactor validations + tech contacts count validation
This commit is contained in:
parent
48e3e716e7
commit
252527c3db
8 changed files with 93 additions and 45 deletions
8
app/validators/object_count_validator.rb
Normal file
8
app/validators/object_count_validator.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
class ObjectCountValidator < ActiveModel::EachValidator
|
||||
def validate_each(record, attribute, value)
|
||||
min, max = options[:min].call, options[:max].call
|
||||
return if value.reject(&:marked_for_destruction?).length.between?(min, max)
|
||||
association = options[:association] || attribute
|
||||
record.errors.add(association, :out_of_range, { min: min, max: max })
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue