Class: ImportableAttachments::ExcelValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/validators/importable_attachments/excel.rb,
app/validators/importable_attachments/excel_validator.rb

Overview

validate attachment is an excel file

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object

:call-seq: validate :record

ensures that the record’s attachment file name has a .xls extension



10
11
12
13
14
15
# File 'app/validators/importable_attachments/excel.rb', line 10

def validate(record)
  extension = record.attachment.io_stream_file_name.split('.').last
  if extension != 'xls'
    record.errors[:attachment] << 'File must be an Excel (.xls) file'
  end
end