2016-03-15 20 views
0

我有一個rails4應用程序,配置文件圖像與carrierwave上傳和S3服務。rails4 carrierwave + S3添加新的圖像版本

我曾經有一個圖像版本(base_thumb)用於調整大小。現在我試圖添加user_thumb,但是如果將代碼從profile.avatar.url(:base_thumb)更改爲profile.avatar.url(:user_thumb),則圖像不會顯示給之前創建配置文件的用戶,因爲該圖像版本不在S3上。

我該如何解決這個問題?

version :base_thumb do 
    process :resize_to_fit => [85, 85] 
end 

version :user_thumb do 
    process :resize_to_fit => [40, 40] 
end 

回答

1

您需要創建每個不同大小的新版本。 Carrierwave爲此提供了一種方法。

你可以在這裏閱讀文檔:https://github.com/carrierwaveuploader/carrierwave#recreating-versions

但本質上你會遇到類似

Profile.find_each do |profile| 
    profile.avatar.recreate_versions! if profile.avatar? 
end 
+0

大聲笑,我不明白我怎麼會在文檔錯過本作。 –

相關問題