I have the following as my FileUploader:
class FileUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
version :thumb, if: :image? do
# For images, do stuff here
end
version :preview, if: :pdf? do
# For pdf, do stuff here
end
protected
def image?(new_file)
new_file.content_type.start_with? 'image'
end
def pdf?(new_file)
new_file.content_type.start_with? 'application'
end
end
I got this from the carrierwave github page. It mostly works, but what If I don't want different versions? I basically just want to do certain processes if it's a pdf, or certain processes if it's an image. I may allow other types of files in the future as well, so it'd be cool if I could have an easy way to do that as well.
For an example, I may want to use an imgoptim if it's an image, and then a pdf optimizing library if it's a pdf, etc.
I tried:
if file.content_type = "application/pdf"
# Do pdf things
elsif file.content_type.start_with? 'image'
# Do image things
end
but get the error: NameError: (undefined local variable or method
file' for FileUploader:Class`