Sha256: 825572c38d652f66c2a6a3044242dc7c362139e550fde83993463f452224e25a
Contents?: true
Size: 625 Bytes
Versions: 78
Compression:
Stored size: 625 Bytes
Contents
class AssetBoxLengthValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) num_in_box = (record.attachments || []).select { |attachment| attachment.box == attribute.to_s.pluralize && attachment.marked_for_destruction? == false }.size if options[:with] record.errors[attribute] << "requires at least #{options[:with]} #{attribute.to_s.pluralize}" if num_in_box < options[:with] elsif options[:in] record.errors[attribute] << "requires #{options[:in].min} to #{options[:in].max} #{attribute.to_s.pluralize}" if options[:in].include?(num_in_box) == false end end end
Version data entries
78 entries across 78 versions & 1 rubygems