class PhotoUploader

encoding: utf-8

Public Class Methods

cache_from_io!(io_string, file_or_name) click to toggle source
# File app/uploaders/photo_uploader.rb, line 31
def self.cache_from_io!(io_string, file_or_name)
  uploader = PhotoUploader.new
  tempfile = if file_or_name.is_a?(String)
    tempfile = Tempfile.new(file_or_name)
    tempfile.write io_string.read#.force_encoding('UTF-8')
    tempfile
  else
    file_or_name.tempfile
  end
  uploader.cache!(tempfile)
  tempfile.close
  tempfile.unlink
  uploader
end

Public Instance Methods

contents_size() { |img| ... } click to toggle source
# File app/uploaders/photo_uploader.rb, line 64
def contents_size
  manipulate! do |img|
    img.resize "#{500}x#{500}" if img[:width] > 500
    img = yield(img) if block_given?
    img
  end
end
default_url() click to toggle source

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

# File app/uploaders/photo_uploader.rb, line 73
def default_url
  "/images/default/" + ["faceless_avatar", "#{version_name}.png"].compact.join('_')
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 app/uploaders/photo_uploader.rb, line 52
def store_dir
  "uploads/#{model.class.base_class.to_s.underscore}/#{mounted_as}/#{model.id}"
end