It turns out that the Carrierwave wiki can be misleading.
I assumed that model.file.file.extension
could be used in full_filename
as well. Turns out it can't: model.file.file
uses the full_filename
to fetch the filename. So this was creating a infinite loop and thus a SystemStackError.
The solution I went for was a simple File.extname
:
class AttachmentUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :file
def store_dir
"uploads/projects/#{model.attachable.project.to_param}/attachments/#{model.id}/#{model.digest}/"
end
version :large do
process resize_to_fit: [700, 700]
def full_filename (for_file = model.file.file)
"large#{File.extname(for_file)}"
end
end
version :thumbnail, from_version: :large do
process resize_to_fill: [250, 250]
def full_filename (for_file = model.file.file.extension)
"thumbnail#{File.extname(for_file)}"
end
end
end