Skip to content

Instantly share code, notes, and snippets.

@nilocoelhojunior
Created January 31, 2018 01:29
Show Gist options
  • Save nilocoelhojunior/5022232f5d737c67ab6174d2fa881bc0 to your computer and use it in GitHub Desktop.
Save nilocoelhojunior/5022232f5d737c67ab6174d2fa881bc0 to your computer and use it in GitHub Desktop.
Carrierwave Fog rename file
class FileUploader < CarrierWave::Uploader::Base
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w(pdf)
end
def size_range
0..10.megabytes
end
def rename!(new_name)
new_path = File.join(File.dirname(file.path), new_name)
old = CarrierWave::SanitizedFile.new file
new_sf = old.move_to(new_path)
model.file.cache!(new_sf)
model.save!
model
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment