Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

27 lines (24 sloc) 0.927 kb
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
Jump to Line
Something went wrong with that request. Please try again.