diff --git a/app/validators/object_count_validator.rb b/app/validators/object_count_validator.rb index 92830b1b0..d2d880fea 100644 --- a/app/validators/object_count_validator.rb +++ b/app/validators/object_count_validator.rb @@ -1,7 +1,9 @@ class ObjectCountValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) min, max = options[:min].call, options[:max].call - return if value.count { |i| !i.marked_for_destruction? }.between?(min, max) + values = value.reject(&:marked_for_destruction?) + + return if values.size.between?(min, max) association = options[:association] || attribute record.errors.add(association, :out_of_range, { min: min, max: max }) end