Module: Paperclip::Validators::ClassMethods
- Defined in:
- lib/paperclip/validators.rb
Instance Method Summary collapse
-
#validates_attachment(*attributes) ⇒ Object
This method is a shortcut to validator classes that is in “Attachment…Validator” format.
Instance Method Details
#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 }
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/paperclip/validators.rb', line 28 def (*attributes) = attributes..dup Paperclip::Validators.constants.each do |constant| if constant.to_s =~ /^Attachment(.+)Validator$/ validator_kind = $1.underscore.to_sym if .has_key?(validator_kind) [:"attachment_#{validator_kind}"] = .delete(validator_kind) end end end validates(*attributes + []) end |