Class: CarrierWaveDirect::Validations::ActiveModel::FilenameFormatValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/carrierwave_direct/validations/active_model.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/carrierwave_direct/validations/active_model.rb', line 23

def validate_each(record, attribute, value)
  if record.new_record? && record.send("has_#{attribute}_upload?") && record.key !~ record.send(attribute).key_regexp
    record.errors.add(
      attribute,
      :carrierwave_direct_filename_invalid,
      :extension_white_list => record.send(attribute).extension_white_list
    )
  end
end