Fix migration that fails on conferences without pictures

CarrierWave documentation:

> Note: `recreate_versions!` will throw an exception on records without
> an image. To avoid this, scope the records to those with images or
> check if an image exists within the block.

Resolves #1976:

    NoMethodError: undefined method `read' for nil:NilClass
    …/carrierwave-1.3.1/lib/carrierwave/uploader/cache.rb:81:in `sanitized_file'
    …/carrierwave-1.3.1/lib/carrierwave/uploader/cache.rb:118:in `cache!'
    …/carrierwave-1.3.1/lib/carrierwave/uploader/versions.rb:234:in `recreate_versions!'
    db/migrate/20171130172334_rebuild_conference_pictures.rb:4:in `block in up'
This commit is contained in:
Andrew Kvalheim 2020-05-11 12:50:34 -07:00 committed by Henne Vogelsang
parent 2051540693
commit 079f609603
No known key found for this signature in database
GPG key ID: 9D6164C2955FADE0

View file

@ -2,7 +2,7 @@
class RebuildConferencePictures < ActiveRecord::Migration
def up
Conference.all.each do |conference|
Conference.where.not(picture: nil).each do |conference|
conference.picture.recreate_versions!
end
end