Scott Watermasysk

Still Learning to Code

CarrierWave and Ruby 1.9.2 and Other Tips

I spent some time yesterday with the excellent CarrierWave gem.

This gem provides a simple and extremely flexible way to upload files from Ruby applications. It works well with Rack based web applications, such as Ruby on Rails.

Everything was going great until I wired up RMagick to enforce some constraints on the image size. Once RMagick was running, anytime I uploaded an image Ruby would segfault and kill the webrick process.

I thought there might be an issue with my ImageMagick install, so I opened up the rails console and manually invoked the uploader and it worked as expected. I little searching around lead me to this post on StackOverflow.

Assuming you are using Homebrew, you can resolve this issue with:


brew remove imagemagick
rm -rf `brew --cache imagemagick`
brew install -f imagemagick --disable-openmp

A couple interesting tips and suggestions on CarrierWave:

  • Check out the RailsCast on CarrierWave screencast. It is a great quick overview and provides enough info to get you up and running in a couple of minutes.
  • To remove an attachment, just include a checkbox with :remove_attribute_name in your form.
  • Don’t forget to add things like :remove_attribute_name and :attribute_name_cache to your attr_accessible. I lost about 30 minutes debugging because I forgot to make this change.