I use carrierwave for my images upload, in my form i added a hidden field for caching like is described in documentation.
= form_for @user, html: {multipart: true} do |f|
%p
= f.label :image, "your image"
= f.file_field :image, id: "img"
= f.hidden_field :image_cache
but the problem is after uploading images and saving record, tmp directory still having all temporary/caching files.
there is a way to clean up the tmp directory ?
i found this post here but can't understand it as well, and there is no simple example explained
Edit
I tried to run this command with console
CarrierWave.clean_cached_files!
it outputs me an array of all files in tmp directory like this:
["/home/medBo/projects/my_project/public/uploads/tmp/1380732930-5006-6671","/home/medBo/projects/my_project/public/uploads/tmp/1380754280-4623-3698" ....
but when i go to see what happens, i find that all files still exists in /tmp (not removed)
i tried to read more in the link above, i found a special considerations about CarrierWave.clean_cached_files! :
Special Considerations
This method breaks uploaders that have more than one version defined. Your first version will be saved, but afterwards the cleanup code will run and remove the tmp file that is used to generate additional versions. In that case, you are better off creating a rake task that cleans out the tmp folders periodically.
what means : "This method breaks uploaders that have more than one version" ? (because i use two versions in my uploader class "thumb and large versions") :
class ImageUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
...
...
version :large do
resize_to_limit(600, 600)
end
version :thumb do
process :crop_image
resize_to_fill(100, 100)
end
...
...
end
I also try to run a task to see if folders inside tmp/ directory will be removed but the task doesn't work :
task :delete_tmp_files do
FileUtils.rm_rf Dir.glob("#{Rails.root}/public/uploads/tmp/*")
end