Class: ActiveStorageValidations::AttachedValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/active_storage_validations/attached_validator.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, _value) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/active_storage_validations/attached_validator.rb', line 5

def validate_each(record, attribute, _value)
  return if record.send(attribute).attached?

  errors_options = {}
  errors_options[:message] = options[:message] if options[:message].present?

  record.errors.add(attribute, :blank, **errors_options)
end