Rails CarrierWave版本不是出于某种原因而创建的

时间:2012-08-23 18:11:03

标签: ruby-on-rails-3 imagemagick carrierwave homebrew

我有以下文件上传器

class ItemImageUploader < CarrierWave::Uploader::Base
  include ::CarrierWave::Backgrounder::Delay
  include CarrierWave::MiniMagick
  include Sprockets::Helpers::RailsHelper
  include Sprockets::Helpers::IsolatedHelper

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  # Provide a default URL as a default if there hasn't been a file uploaded:
  def default_url
    asset_path("fallback/" + [version_name, "image.png"].compact.join('_'))
  end

  def cache_dir
      "uploads/tmp"
  end

  # Create different versions of your uploaded files:
  version :thumb do
    process :resize_to_fill => [80,80]
  end

  def extension_white_list
    %w(jpg jpeg gif png)
  end

图片类

class Picture < ActiveRecord::Base
  belongs_to :imageable, :polymorphic => true
  mount_uploader :image, ItemImageUploader
  process_in_background :image
  validates_presence_of :image

  def copy
    Picture.new(:image => self.image)
  end

以下配置在carrier_wave.rb初始化文件中:

CarrierWave.configure do |config|
config.enable_processing = true
    #config.permissions = 0666
    #config.directory_permissions = 0777
    config.storage = :file
end

图片已正确上传,但未创建缩略图,未发生任何错误。请指教。

2 个答案:

答案 0 :(得分:3)

我自己就碰到了这个。正如评论所示,使用carrierwave_backgrounder会导致此问题。您可以在documentation

中看到它

process_in_background - This stores the original file with no processing/versioning.

无法解决问题,但我认为我会验证问题。

答案 1 :(得分:0)

今天我挣扎了几个小时,因为我遇到了同样的问题。上传原始版本可行,但未调整大小。它在本地工作,但不在我的生产机器上。希望有同样问题的人会在这个问题上遇到麻烦,并节省一些时间。

原来我的ImageMagick版本没有使用正确的委托构建,这是$ convert -version的输出:

Version: ImageMagick 6.9.1-10 Q16 x86_64 2015-08-01 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC OpenMP 
Delegates (built-in): zlib

我使用这个答案来安装代理并构建一个新版本的ImageMagick:ImageMagick missing decode delegates

之后,使用$ convert -version

提取ImageMagick信息
Version: ImageMagick 6.9.1-10 Q16 x86_64 2015-08-01 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC OpenMP 
Delegates (built-in): bzlib djvu fontconfig freetype gvc jbig jng jpeg lcms lqr lzma openexr png tiff wmf x xml zlib

现在我来罗林&#39;!