class MiniPaperclip::Validators::ContentTypeValidator

Public Instance Methods

validate_each(record, attribute, value) click to toggle source
# File lib/mini_paperclip/validators/content_type_validator.rb, line 6
def validate_each(record, attribute, value)
  allows = Array(options[:content_type])
  attachment_content_type_name = "#{attribute}_content_type"
  attachment_content_type = record.read_attribute_for_validation(attachment_content_type_name)
  if attachment_content_type && !allows.include?(attachment_content_type)
    record.errors.add(attribute, :invalid)
    record.errors.add(attachment_content_type_name, :invalid)
  end
end