Search code examples
ruby-on-railsrubycarrierwaveminimagick

Carrierwave including MiniMagick -> uploads no longer work


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

  • Windows
  • ImageMagick installed
  • ruby 2.2.4p230 (2015-12-16 revision 53155) [x64-mingw32]
  • CarrierWave 0.10.0 and Carrierwave-Mongoid 0.8.0

Solution

  • I managed to make it work. I'm not really sure what was the key step, but amongst other

    • I opened ImageMagick for Windows once (I know some programs generate additional config files after first start), and I tried opening/saving a photo with the GUI
    • I deleted previously uploaded Carrierwave files
    • I ran rails s once in administrator mode (now it runs fine even without)