class Uppr::Attachment

Public Instance Methods

delete_tmp_dir(new_file) click to toggle source
# File lib/uppr/attachment.rb, line 26
def delete_tmp_dir(new_file)
  # make sure we don't delete other things accidentally by checking the name pattern
  if @cache_id_was.present? && @cache_id_was =~ /\A[\d]{8}\-[\d]{4}\-[\d]+\-[\d]{4}\z/
    FileUtils.rm_rf(File.join(root, cache_dir, @cache_id_was))
  end
end
extension_white_list() click to toggle source

Add a white list of extensions which are allowed to be uploaded. For images you might use something like this:

# File lib/uppr/attachment.rb, line 53
def extension_white_list
  %w(zip rar pdf doc)
end
remember_cache_id(new_file) click to toggle source

store! nil's the cache_id after it finishes so we need to remember it for deletion

# File lib/uppr/attachment.rb, line 22
def remember_cache_id(new_file)
  @cache_id_was = cache_id
end
store_dir() click to toggle source

Override the directory where uploaded files will be stored. This is a sensible default for uploaders that are meant to be mounted:

# File lib/uppr/attachment.rb, line 14
def store_dir
  "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end