rails4 carrierwave + S3 添加新镜像版本

rails4 carrierwave + S3 adding new image version

我有一个 rails4 应用程序,个人资料图像使用载波上传并由 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

您需要创建每个不同尺寸的新版本。 Carrierwave 有一个方法可以做到这一点。

您可以在此处阅读文档:https://github.com/carrierwaveuploader/carrierwave#recreating-versions

但基本上你会运行类似

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