I am building an application where i have a file with original, medium and thumbnail size images. I am using carrierwave to accomplish this, and I need to remove all versions of the file from Rackspace Cloud Files:
class StyleImageUploader < CarrierWave::Uploader::Base
version :medium do
process :resize_to_limit => [460, 460]
end
version :thumb do
process :resize_to_limit => [100, 100]
end
def filename
"#{Digest::MD5.hexdigest(original_filename . Time.now.to_s)}.#{file.extension}" if original_filename
end
end
However, when i do a destroy through console, it is only removing the original version... How do i go about deleting all the versions? I also get this error in console, but it still does remove the single file
#<Fog::Storage::Rackspace::NotFound: Fog::Storage::Rackspace::NotFound>
Controller destroy method:
class ImagesController < ApplicationController
def destroy
@image = Image.find(params[:id])
@image.destroy
render :json => true
end
end
The problem was in the filename method... its naming the files differently, 1 second off as the Time.now is recalled. It looks as though the filename method runs on each version method, which the timestamp is off.
Solution: https://github.com/jnicklas/carrierwave/wiki/How-to%3A-Use-a-timestamp-in-file-names