I have a Rails app with Carrierwave and I am using MiniMagick for image processing.
Whenever I add include CarrierWave::MiniMagick
in my Uploader files, the upload just stops working, without any hint of error, and the application flow resumes without updating the uploaded images
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process resize_to_fill: [50, 50]
end
def filename
"avatar.#{file.extension}" if original_filename if original_filename
end
end
My User class has the following lines
attr_accessor :avatar, :avatar_cache
mount_uploader :avatar, ::AvatarUploader
My view
<%= f.label(:avatar, t(:avatar)) %>
<%= image_tag(user.avatar_url) if user.avatar? %>
<%= f.file_field :avatar %>
<%= f.hidden_field :avatar_cache %>
When I comment out the include line and the resize_to_fill line in the uploader, everything works well.
This is hard to debug, I have tried uploading the avatar through .store!
the console but the output is a weird [:store_versions!]
u = User.first
u.avatar # Contains 'old.jpg' ( Which I uploaded with the buggy lines commented, and changed the filename to 'old')
u.avatar.store!(File.new("C:\\somejpeg.jpg"))
=> [:store_versions!]
u.avatar # Still shows old 'me.jpg'
Config
I managed to make it work. I'm not really sure what was the key step, but amongst other
rails s
once in administrator mode (now it runs fine even without)