12
votes

I'm trying to recreate the images that I have uploaded using the following in my model...

  Post.all.each do |ym| 
      ym.avatar.cache_stored_file! 
      ym.avatar.retrieve_from_cache!(ym.avatar.cache_name) 
      ym.avatar.recreate_versions! 
      ym.save! 
  end

Unfortunately, I get the following error....

(undefined method `body' for nil:NilClass):

My uploader is named AvatarUploader and is for my Post model. Any advice on how to fix this?

1
I think you are supposed to put that code in the uploader and not the Post model.noob
Can you add a backtrace?ghayes
Is it on a read-only server?ErvalhouS

1 Answers

0
votes

I've ran with a similar problem when using async processing on a read-only server(Heroku). In my case there was a problem when defining file size which I resolved monkey-patching def size from fog file class:

module CarrierWave
  module Storage
    class Fog < Abstract
      class File
        def size
          file.nil? ? 0 : file.content_length
        end
      end
    end
  end
end

I could help you more if the issue still persists and when you post more details from your backtrace and gems configuration.