2 task :upgrade_avatars => :environment do
3 User.active.where.not(:image_file_name => nil).in_batches.each_record do |user|
4 io = File.open(user.image.path)
5 filename = user.image.original_filename
6 content_type = if user.image.content_type.nil?
7 MimeMagic.by_magic(io)&.type
9 user.image.content_type
12 user.avatar.attach(:io => io, :filename => filename, :content_type => content_type)