Sean Magyar
Sean Magyar

Reputation: 2380

rails4 carrierwave + S3 adding new image version

I have a rails4 app, profile images are uploaded with carrierwave and served by S3.

I used to have one image version (base_thumb) for resizing. Now I'm trying to add user_thumb, but if I change the code from profile.avatar.url(:base_thumb) to profile.avatar.url(:user_thumb) then the image is not displayed to users who created profile earlier since that image version is not on S3.

How can I solve this issue?

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

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

Upvotes: 0

Views: 87

Answers (1)

trh
trh

Reputation: 7339

You'll need to create new versions of each different size. Carrierwave has a method for this.

You can read the doc here: https://github.com/carrierwaveuploader/carrierwave#recreating-versions

but essentially you will run something like

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

Upvotes: 1

Related Questions