LoginSignup
0
0

More than 5 years have passed since last update.

Carrierwaveでアップロードした画像に特定の新しいバージョンを追加する

Last updated at Posted at 2016-09-25

例えば、こういうバージョンを作って運用してたとします。


  version :thumb_1000 do
    process :resize_to_fit => [1000, 1000]
  end

あとで別のバージョンを追加しようとした場合、こう書きますが

  version :thumb_600 do
    process :resize_to_fit => [600, 600]
  end

  version :thumb_1000 do
    process :resize_to_fit => [1000, 1000]
  end

これで既存のファイルからバージョンを作ることができます。


User.all.each { |user| user.image.recreate_versions! }

このメソッドは既にあるバージョンも作り直すため、引数でバージョンを与えるとそのバージョンだけ作ってくれます。


User.all.each { |user| user.image.recreate_versions!(:thumb_600) }

削除するときは


User.all.each do |user|
  path = File.delete(user.image.thumb_600.current_path)
  File.delete(path) if File.exists?(path.to_s)
end

こんな感じかなぁ。。スマートじゃないけど。。

0
0
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
0
0