Class: AssetBoxPresenceValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/validators/asset_box_presence_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



2
3
4
5
# File 'lib/validators/asset_box_presence_validator.rb', line 2

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
  record.errors[attribute] << "can't be blank" if num_in_box == 0
end