What is the best way to add this functionality ?
validates_attachment_extension_type :myfile, :extensions =>
GOOD_EXTENSIONS
I tried replicating the process of the
validates_attachment_content_type but for some reason couldn't get it
to work , here is what I tried:
in paperclip.rb
def validates_attachment_extension_type name, options = {}
attachment_definitions[name][:validations] << lambda do |
attachment, instance|
valid_types = [options[:extensions]].flatten
unless attachment.original_filename.nil?
unless options[:extensions].blank?
ext = instance[:"#{name}_xtension"]
unless valid_types.any?{|t| t === ext }
options[:message] || "is not one of the allowed file
types.(was #{ext})"
end
end
end
end
In attachment.rb
@instance[:"#{@name}_file_size"] = uploaded_file.size.to_i
@instance[:"#{@name}_updated_at"] = Time.now
@instance[:"#{@name}_xtension"] =
(uploaded_file.original_filename.match(/\.(\w+)$/)[1] rescue "octet-
stream").downcase
@dirty = true
def queue_existing_for_delete #:nodoc:
return unless file?
logger.info("[paperclip] Queueing the existing files for #{name}
for deletion.")
@queued_for_delete += [:original, *@styles.keys].uniq.map do |
style|
path(style) if exists?(style)
end.compact
@instance[:"#{@name}_file_name"] = nil
@instance[:"#{@name}_content_type"] = nil
@instance[:"#{@name}_file_size"] = nil
@instance[:"#{@name}_updated_at"] = nil
@instance[:"#{@name}_xtension"] = nil
end
end
Thanks