If you ever wondered how to check for file if exist while you were using carrierwave gem with storage on amazon S3 here is how.
Assuming you have User class:
class User < ActiveRecord::Base
mount_uploader :avatar, AvatarUploader
end
and uploader class
class AvatarUploader < CarrierWave::Uploader::Base
storage :fog
end
then only thing that you have to do is this
user = User.first
user.avatar.file.exists?
thats it. I kind of assumed that it should be simple avatar.exist? but you have to get fog instance of file to be able to access exists? method.
Leave a Reply