LoginSignup
1
1

More than 5 years have passed since last update.

CarrierWaveのthumbなどの別バージョンを再出力するのはrecreate_versions!メソッド

Posted at

version :thumb等を追加したい場合は以下のような感じ

app/uploaders/photo_image_uploader.rb
class PhotoImageUploader < CarrierWave::Uploader::Base
  ()
  version :thumb do
    process convert: "jpg"
    process resize_to_fit: [190, 120]
    def full_filename(for_file)
      super(for_file).sub(/\.[^\.]+$/, '.jpg')
    end
  end
end

記載から省いてますが、pietなど使ってサムネイル用意する時にoptimizeも併せて実施しています。

追加した後に以下のコマンドで再出力

rails r 'Photo.all.order("id desc").each{|photo| photo.image.recreate_versions! if photo.image.present?}'
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1