Sha256: c1b13669ecf88535de1cb86f68b0daf5bb54c8425f7477bc952f993c2b6bd4eb
Contents?: true
Size: 1.03 KB
Versions: 1
Compression:
Stored size: 1.03 KB
Contents
class AttachmentSizeValidator < RailsUploads::Validators::Base # validates :attr, :attachment_size => { :in => 0..4.megabytes } def validate_each(record, attribute, value) if value.present? and not value.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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rails_uploads-0.1.5 | lib/rails_uploads/validators/attachment_size_validator.rb |