1

我有这两个上传者: https ://gist.github.com/4180193

class ImageUploader < CarrierWave::Uploader::Base

  include CarrierWave::MiniMagick
  include Sprockets::Helpers::RailsHelper
  include Sprockets::Helpers::IsolatedHelper
  storage :file

  def store_dir
    "images/#{model.class.to_s.underscore}/#{model.slug}"
  end

  def default_url
    asset_path("fallback/" + [version_name, "image.jpg"].compact.join('_'))
  end

  def self.get_width(span)
    grid_column_width = 110
    grid_gutter_width = 10
    return grid_column_width if span <= 0 or span > 8
    (span*grid_column_width) + ((span>1 ? span-1 : 0)*grid_gutter_width)
  end

  def self.get_height(width)
    ratio = 180/150
    width/ratio
  end

  def self.dims(span)
    width = get_width(span)
    [width, get_height(width)]
  end

  version :xlarge do
    process :resize_to_limit => dims(8)
    process :convert => :jpg
  end

  version :large do
    process :resize_to_limit => dims(4)
    process :convert => :jpg
  end

  version :medium do
    process :resize_to_limit => dims(2)
    process :convert => :jpg
  end

  version :small do
    process :resize_to_limit => dims(1)
    process :convert => :jpg
  end

  version :xsmall do
    process :resize_to_limit => dims(0.5)
    process :convert => :jpg
  end

  def extension_white_list
    %w(jpg jpeg gif png tiff tif)
  end

  def filename
    "image.jpg" if original_filename
  end

end

class AmbianceImageUploader < ImageUploader
  version :header do
    process :resize_to_fill => [get_width(6), 350+10]
    process :convert => :jpg
  end

  def filename
    "ambiance.jpg" if original_filename
  end

end

但是,当我使用 AmbianceUploader 上传内容时,不会创建 ImageUploader 中定义的版本。我将如何解决这个问题?

PS:

[2] pry(main)> AmbianceImageUploader.versions
=> {:xlarge=>{:uploader=>#<Class:0x007fde61b5b520>, :options=>{}},
 :large=>{:uploader=>#<Class:0x007fde61f90500>, :options=>{}},
 :medium=>{:uploader=>#<Class:0x007fde5ee166c8>, :options=>{}},
 :small=>{:uploader=>#<Class:0x007fde5ec492c8>, :options=>{}},
 :xsmall=>{:uploader=>#<Class:0x007fde5d8687b8>, :options=>{}},
 :header=>{:uploader=>#<Class:0x007fde61ac1808>, :options=>{}}}

所以版本就在那里,只是出于某种原因他们不关心......

4

0 回答 0