Sha256: 77bb0dafb8eb071478574c69e84b2ebc9dbd928d842f2694b05cc6bd1204052c
Contents?: true
Size: 927 Bytes
Versions: 15
Compression:
Stored size: 927 Bytes
Contents
require 'active_model/validations/presence' module Paperclip module Validators class AttachmentPresenceValidator < ActiveModel::Validations::PresenceValidator def validate(record) [attributes].flatten.map do |attribute| if record.send(:read_attribute_for_validation, "#{attribute}_file_name").blank? record.errors.add(attribute, :blank, options) end end end end module HelperMethods # Places ActiveRecord-style validations on the presence of a file. # Options: # * +if+: A lambda or name of an instance method. Validation will only # be run if this lambda or method returns true. # * +unless+: Same as +if+ but validates if lambda or method returns false. def validates_attachment_presence(*attr_names) validates_with AttachmentPresenceValidator, _merge_attributes(attr_names) end end end end
Version data entries
15 entries across 15 versions & 2 rubygems