2011-12-27 113 views
2

我正在尝试使用carrierwave来管理图像。我的问题是,我上传的图像的所有版本都已创建,但尺寸完整。代码:Carrierwave没有使用rmagick的大小版本

class TechnologyImageUploader < CarrierWave::Uploader::Base 

    # Include RMagick or MiniMagick support: 
    include CarrierWave::RMagick 

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

    # Process files as they are uploaded: 
    #process :scale => [100, 100] 

    version :small do 
    process :resize_to_fit => [25,25] 
    end 
    version :medium do 
    process :resize_to_fit => [50,50] 
    end 
end 

所有图像版本都显示为原始上传的大小。

+0

我面临着同样的问题。你修好了吗?如果你能分享这个解决方案,将会非常感激。谢谢 – svs 2012-02-17 12:34:51

+0

你好,同样在这里。我的意思是如果我只指定1个版本,它的工作原理是正确的,但是当多个版本出现时,它只会产生一个版本。这可能是一些版本bug可能? o.O – p1100i 2012-02-26 13:18:11

回答

1

不知道你们是否有这个问题,因为我有同样的原因,但也许。 我需要将上传的文件移动到一个私人文件夹,我相信你也是这样做的。

我上传后我想删除缓存我做什么用:

after :store, delete_cache 

def delete_cache(new_file) 
    FileUtils.rm_rf %{#{Rails.root.to_s}/public/uploads} 
end 

这样做的问题,是创建一个版本之后,在后:商店将被触发,因此应用程序中移除了缓存目录,所以其他版本的方法不能读取该文件了。

对我来说暂时的解决方案是将cache_dir移动到一个私人文件夹。我需要以不同的方式后空的,我需要弄清楚,所以:

def cache_dir 
    %{#{Rails.root.to_s}/tmp/uploads} 
end 
1

我的问题的解决方案是,Rails环境中的服务器和“发展上命名为“分期” '在Mac上。

文件config/initializers/carrierwave.rb(第4行)处的第4行禁用了名为'staging'的环境的载波处理。

为了使处理工作,我需要能够与这条线:

config.enable_processing = true 
0

我有我的应用程序一个莫名其妙类似的问题。 虽然我想我知道了,当使用版本时, 将每个'进程'设置为一个版本是有帮助的...... 否则我已经注意到有些方法'覆盖其他'... 奇怪。

class ImageUploader < CarrierWave::Uploader::Base 
    include CarrierWave::RMagick 

    if Rails.env == "production" 
    storage :aws 
    else 
    storage :file 
    end 

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

    #this is the 'first' process, 'while you upload', the one that seems to be an issue 
    process resize_to_fill: [228, 250] 


    version :industry do 
    process resize_to_fit: [228, 250] 
    end 

    version :portrait do 
    process resize_to_fill: [360, 200] 
    end 

    version :modal do 
    process resize_to_fill: [330, 300] 
    end 

end 

这将继而成为::

class ImageUploader < CarrierWave::Uploader::Base 
    include CarrierWave::RMagick 

    if Rails.env == "production" 
    storage :aws 
    else 
    storage :file 
    end 

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

    #i put everything as a version and it sorts the problem out.. 

    version :base do 
    process resize_to_fill: [228, 250] 
    end 

    version :industry do 
    process resize_to_fit: [228, 250] 
    end 

    version :portrait do 
    process resize_to_fill: [360, 200] 
    end 

    version :modal do 
    process resize_to_fill: [330, 300] 
    end 

end 

我希望这是 '真',将是有益的其他用户

马林

相关问题