episode-134/store/vendor/plugins/paperclip/lib/paperclip.rb
# Places ActiveRecord-style validations on the content type of the file assigned. The
# possible options are:
# * +content_type+: Allowed content types.  Can be a single content type or an array.
#   Each type can be a String or a Regexp. It should be noted that Internet Explorer uploads
#   files with content_types that you may not expect. For example, JPEG images are given
#   image/pjpeg and PNGs are image/x-png, so keep that in mind when determining how you match.
#   Allows all by default.
# * +message+: The message to display when the uploaded file has an invalid content type.
Places ActiveRecord-style validations on the content type of the file assigned. The
possible options are:
+content_type+: Allowed content types.  Can be a single content type or an array.
Each type can be a String or a Regexp. It should be noted that Internet Explorer uploads
files with content_types that you may not expect. For example, JPEG images are given
image/pjpeg and PNGs are image/x-png, so keep that in mind when determining how you match.
Allows all by default.
+message+: The message to display when the uploaded file has an invalid content type.
Places ActiveRecord - style validations on the content type of the file assigned . The possible options are : + content_type + : Allowed content types . Can be a single content type or an array . Each type can be a String or a Regexp . It should be noted that Internet Explorer uploads files with content_types that you may not expect . For example JPEG images are given image / pjpeg and PNGs are image / x - png so keep that in mind when determining how you match . Allows all by default . + message + : The message to display when the uploaded file has an invalid content type .
def validates_attachment_content_type name, options = {}
      attachment_definitions[name][:validations] << lambda do |attachment, instance|
        valid_types = [options[:content_type]].flatten
        unless attachment.original_filename.blank?
          unless options[:content_type].blank?
            content_type = instance[:"#{name}_content_type"]
            unless valid_types.any?{|t| t === content_type }
              options[:message] || "is not one of the allowed file types."
            end
          end
        end
      end
    end
def validates_attachment_content_type name , options = { } attachment_definitions [ name ] [ :validations ] << lambda do | attachment , instance | valid_types = [ options [ :content_type ] ] . flatten unless attachment . original_filename . blank? unless options [ :content_type ] . blank? content_type = instance [ :" #{ name } _content_type " ] unless valid_types . any? { | t | t === content_type } options [ :message ] || "is not one of the allowed file types." end end end end end
Places ActiveRecord-style validations on the content type of the file assigned.
Places ActiveRecord - style validations on the content type of the file assigned .
name
options