Sha256: 6dfb926d0c8bc6c03ac8a6b6b03e02b757bc09d273dcdaa92b1806a3c6f80700
Contents?: true
Size: 982 Bytes
Versions: 2
Compression:
Stored size: 982 Bytes
Contents
class AttachmentSizeValidator < RailsUploads::Validators::Base def validate_each(record, attribute, value) if value.present? and not value.send(:is_default?) if options.has_key? :in unless options[:in].include? value.size add_error record, attribute, 'attachment_size_in', greater_than: options[:in].begin, less_than: options[:in].end end else if options.has_key? :less_than and value.size > options[:less_than] add_error record, attribute, 'attachment_size_less_than', less_than: options[:less_than] end if options.has_key? :greater_than and value.size < options[:greater_than] add_error record, attribute, 'attachment_size_greater_than', greater_than: options[:greater_than] end end end end protected def add_error(record, attribute, type, options) super(record, attribute, "errors.messages.#{type}", options) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rails_uploads-0.2.1 | lib/rails_uploads/validators/attachment_size_validator.rb |
rails_uploads-0.2.0 | lib/rails_uploads/validators/attachment_size_validator.rb |