Class: CarrierWaveDirect::Validations::ActiveModel::IsUploadedValidator

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



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/carrierwave_direct/validations/active_model.rb', line 65

def validate_each(record, attribute, value)
  if record.new_record?
    unless (record.send("has_#{attribute}_upload?") || record.send("has_remote_#{attribute}_net_url?"))
      record.errors.add(
        attribute,
        :carrierwave_direct_upload_missing
      )
      record.errors.add(
        :"remote_#{attribute}_net_url",
        :blank
      )
    end
  end
end