Sha256: 1387dad88c38a3d047c504aec472ca1ec36887c8bfeb18cc6f8a8b8878a756f0
Contents?: true
Size: 1.19 KB
Versions: 14
Compression:
Stored size: 1.19 KB
Contents
require 'fileutils' class FileUploader < CarrierWave::Uploader::Base include CarrierWave::MiniMagick storage :file after :remove, :delete_empty_upstream_dirs version :normalized, :if => :image? do process :resize_to_limit => [1024,768] end version :preview, :if => :image? do process :resize_to_limit => [100,100] end def timestamp time=if model model.created_at || Time.now else Time.now end time.strftime("%Y%m") end # With slash in first place it will be absolute url, otherwise relative to Rails.root+"/public" def store_dir if model "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{timestamp}/#{model.id}" else "uploads/misc" end end def delete_empty_upstream_dirs path = ::File.expand_path(store_dir, root) #FileUtils.rm_rf path # always remove # path = ::File.expand_path(base_store_dir, root) Dir.delete(path) # fails if path not empty dir rescue SystemCallError true # nothing, the dir is not empty end def image?(file) File.extname(file.filename.to_s).match(/jpg|JPG|jpeg|JPEG|png|PNG|gif|GIF/) end end
Version data entries
14 entries across 14 versions & 1 rubygems