Module: SimpleAttachments::AttachmentModel::ClassMethods

Defined in:
lib/simple_attachments/attachment_model.rb

Instance Method Summary collapse

Instance Method Details

#validates_filesize(options) ⇒ Object

Validate filesize. Syntax is identical to numericality validator. Filesize is given in bytes.

validates_filesize :less_than_or_equal_to => 12e6, :message => 'file is too large'

:message is optional.



47
48
49
50
# File 'lib/simple_attachments/attachment_model.rb', line 47

def validates_filesize(options)
  options[:message] ||= I18n.t('simple_attachments.file_is_too_large')
  validates :filesize, :numericality => options
end

#validates_mimetype(types, options = {}) ⇒ Object

Validate mimetype of uploaded file.

validates_mimetype %w(image/png image/gif image/jpeg), :message => 'should be an image'

:message is optional.



36
37
38
39
# File 'lib/simple_attachments/attachment_model.rb', line 36

def validates_mimetype(types, options = {})
  options[:message] ||= I18n.t('simple_attachments.mimetype_isnt_allowed')
  validates :mimetype, :inclusion => { :in => types, :message => options[:message] }
end