class Uppr::Image

Public Instance Methods

default_url() click to toggle source

Provide a default URL as a default if there hasn't been a file uploaded:

# File lib/uppr/image.rb, line 22
def default_url
  ActionController::Base.helpers.asset_path('fallback/' + [version_name, 'default.png'].compact.join('_'))
end
delete_tmp_dir(new_file) click to toggle source
# File lib/uppr/image.rb, line 34
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/image.rb, line 82
def extension_white_list
  %w(jpg jpeg gif png)
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/image.rb, line 30
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/image.rb, line 17
def store_dir
  "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end