2011-12-27 14 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 

我希望這是 '真',將是有益的其他用戶

馬林

相關問題