Sha256: e82dec4cfe0dc0d54c55f0189b7454f3062647b5e2ccdfbfb92cc9718b2307b8
Contents?: true
Size: 858 Bytes
Versions: 2
Compression:
Stored size: 858 Bytes
Contents
class FileUploader < CarrierWave::Uploader::Base storage :file after :remove, :delete_empty_upstream_dirs 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 "upload/#{model.class.to_s.underscore}/#{timestamp}/#{model.id}" else "upload/misc" end end def delete_empty_upstream_dirs path = ::File.expand_path(store_dir, root) Dir.delete(path) # fails if path not empty dir # 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 end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
lolita-file-upload-0.2.3 | app/uploaders/file_uploader.rb |
lolita-file-upload-0.2.2 | app/uploaders/file_uploader.rb |