Created
January 31, 2018 01:29
-
-
Save nilocoelhojunior/5022232f5d737c67ab6174d2fa881bc0 to your computer and use it in GitHub Desktop.
Carrierwave Fog rename file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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