0
@@ -144,6 +144,8 @@ module Paperclip
0
define_method "#{name}?" do
0
! attachment_for(name).original_filename.blank?
0
+ add_validator_to_context(opts_from_validator_args([name]), [name], Paperclip::Validate::CopyAttachmentErrors)
0
# Places ActiveRecord-style validations on the size of the file assigned. The
0
@@ -152,29 +154,9 @@ module Paperclip
0
# * +less_than+: equivalent to :in => 0..options[:less_than]
0
# * +greater_than+: equivalent to :in => options[:greater_than]..Infinity
0
# * +message+: error message to display, use :min and :max as replacements
0
- #def validates_attachment_size(*fields)
0
- # opts = opts_from_validator_args(fields)
0
- # add_validator_to_context(opts, fields, Paperclip::Validate::SizeValidator)
0
- def validates_attachment_size name, options = {}
0
- @@attachment_definitions[name][:validations] << lambda do |attachment, instance|
0
- unless options[:greater_than].nil?
0
- options[:in] = (options[:greater_than]..(1/0)) # 1/0 => Infinity
0
- unless options[:less_than].nil?
0
- options[:in] = (0..options[:less_than])
0
- unless attachment.original_filename.blank? || options[:in].include?(instance.send(:"#{name}_file_size").to_i)
0
- min = options[:in].first
0
- max = options[:in].last
0
- options[:message].gsub(/:min/, min.to_s).gsub(/:max/, max.to_s)
0
- "file size is not between #{min} and #{max} bytes."
0
+ def validates_attachment_size(*fields)
0
+ opts = opts_from_validator_args(fields)
0
+ add_validator_to_context(opts, fields, Paperclip::Validate::SizeValidator)
0
# Adds errors if thumbnail creation fails. The same as specifying :whiny_thumbnails => true.
0
@@ -183,39 +165,18 @@ module Paperclip
0
# Places ActiveRecord-style validations on the presence of a file.
0
- #def validates_attachment_presence(*fields)
0
- # opts = opts_from_validator_args(fields)
0
- # add_validator_to_context(opts, fields, Paperclip::Validate::RequiredFieldValidator)
0
- def validates_attachment_presence name, options = {}
0
- @@attachment_definitions[name][:validations] << lambda do |attachment, instance|
0
- if attachment.original_filename.blank?
0
- options[:message] || "must be set."
0
+ def validates_attachment_presence(*fields)
0
+ opts = opts_from_validator_args(fields)
0
+ add_validator_to_context(opts, fields, Paperclip::Validate::RequiredFieldValidator)
0
# Places ActiveRecord-style validations on the content type of the file assigned. The
0
# possible options are:
0
# * +content_type+: Allowed content types. Can be a single content type or an array. Allows all by default.
0
# * +message+: The message to display when the uploaded file has an invalid content type.
0
- #def validates_attachment_content_type(*fields)
0
- # opts = opts_from_validator_args(fields)
0
- # add_validator_to_context(opts, fields, Paperclip::Validate::ContentTypeValidator)
0
- def validates_attachment_content_type name, options = {}
0
- @@attachment_definitions[name][:validations] << lambda do |attachment, instance|
0
- valid_types = [options[:content_type]].flatten
0
- unless attachment.original_filename.nil?
0
- unless options[:content_type].blank?
0
- content_type = instance.send(:"#{name}_content_type")
0
- unless valid_types.any?{|t| t === content_type }
0
- options[:message] #|| ActiveRecord::Errors.default_error_messages[:inclusion]
0
+ def validates_attachment_content_type(*fields)
0
+ opts = opts_from_validator_args(fields)
0
+ add_validator_to_context(opts, fields, Paperclip::Validate::ContentTypeValidator)
0
# Returns the attachment definitions defined by each call to has_attached_file.
Comments
No one has commented yet.