Method: Paperclip::Validators::ClassMethods#validates_attachment
- Defined in:
- lib/paperclip/validators.rb
#validates_attachment(*attributes) ⇒ Object
This method is a shortcut to validator classes that is in “Attachment…Validator” format. It is almost the same thing as the validates
method that shipped with Rails, but this is customized to be using with attachment validators. This is helpful when you’re using multiple attachment validators on a single attachment.
Example of using the validator:
:avatar, :presence => true,
:content_type => { :content_type => "image/jpg" },
:size => { :in => 0..10.kilobytes }
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/paperclip/validators.rb', line 35 def (*attributes) = attributes..dup Paperclip::Validators.constants.each do |constant| if constant.to_s =~ /\AAttachment(.+)Validator\z/ validator_kind = $1.underscore.to_sym if .has_key?(validator_kind) = .delete(validator_kind) = {} if == true = .slice(:if, :unless) Array.wrap().each do || method_name = Paperclip::Validators.const_get(constant.to_s).helper_method_name send(method_name, attributes, .merge()) end end end end end |