我的目的是在一个uploader里面可以同时上传视频和pdf,同时可以截图,视频的截使用gem 'carrierwave-video-thumbnailer'这个gem.

方法如下:

{% highlight ruby %}
version :thumb, :if => :thumbable? do
process :efficient_conversion => [640, 960], :if => :pdf?
process thumbnail: [{format: 'png', quality: 7, size:112, strip: false, square:false, logger: Rails.logger}], :if => :video?
def full_filename for_file
png_name for_file, version_name
end
end

version :large, :if => :thumbable? do
process :efficient_conversion => [640, 960], :if => :pdf?
process thumbnail: [{format: 'png', quality: 7, size:800, strip: false, square:false, logger: Rails.logger}], :if => :video?
def full_filename for_file
png_name for_file, version_name
end
end

def thumbable?(file)
pdf?(file) || video?(file)
end

protected
def video?(new_file)
new_file.content_type.end_with? '/mp4'
end

def pdf?(new_file)
  new_file.content_type.end_with? '/pdf'
end

{% endhighlight %}
--END--