CarrierWave,版本不为空

时间:2019-07-03 15:49:26

标签: ruby carrierwave

我在相应的上传器上向现有模型添加了版本部分

class MyUploader < CarrierWave::Uploader::Base

  include CarrierWave::MimeTypes
  include CarrierWaveDirect::Uploader

  # this section is new 
  version :preview, if: :pdf? do
    process :only_first_page
    process :set_png_content_type
    process resize_to_limit: [1024, 1024]
    process convert: :png

    def full_filename(*args)
      super.chomp(File.extname(super)) + '.png'
    end
  end

  ...
end

class Attachment < AR::Base
  ...
  mount_uploader :source, MyUploader
  ...
end

我希望相应模型的预览为空

attachment.source.preview #=> 
=> #<MyUploader::Uploader47346938716880:0x00561fa344d810
 @cache_id="1562167039-18287-6236",
 @file=
  #<CarrierWave::SanitizedFile:0x00561fa35c9018
   @content_type="application/pdf",
   @file="path_to_file",
   @original_filename=nil>,
 @filename="filename",
 @model=
  #<Attachment:0x00561fa3187ce8
   ...
 ...

我没有对此运行recreate_versions!

为什么它没有空preview

0 个答案:

没有答案