文件上传pdf问题

时间:2015-06-07 17:10:30

标签: ruby-on-rails ruby image pdf file-upload

我正在使用carrierwave,minimagick和Rails 4。

我有一个类似于:

的FileUploader
class FileUploader < CarrierWave::Uploader::Base
   include CarrierWave::MiniMagick

   version :thumb, if: :image? do
      process :resize_to_limit => [50, 50]
   end

   version :thumb, unless: :image? do
      process :cover    
      process :resize_to_fill => [50, 50, Magick::NorthGravity]
      process :convert => 'png'
   end

   protected

   def image?(new_file)
      new_file.content_type.start_with? 'image'
   end

   def cover 
      manipulate! do |frame, index|
         frame if index.zero?
      end
   end

end

如果上传了pdf,我正在尝试创建第一页的thumb png版本。如果上传了图片,我正在调整大小并保存它的拇指版本。

我现在收到错误:NameError (uninitialized constant FileUploader::Magick),但是当我带走unless

的块时它会起作用

1 个答案:

答案 0 :(得分:1)

Magick::NorthGravity常量是rmagick gem的一部分(请参阅here),而不是mini_magick的一部分。

相关问题