08 March 2011

Migrate Attachment_fu to CarrierWave : UploaderFu

Carrierwave is my favorite gem for handling uploads and image thumbnail generation (attachment_fu died of old age and paperclip suffers from hashitis, not a pretty picture)

Anyway our imagebank was still on attachment_fu even though I upgraded to rails3 months ago. We couldn't add images and going through some dirty hacks to resuscitate attachment_fu was too much black magic.

So CarrierWave it was.

But how to stick to attachment_fu's naming convention. CarrierWave has a nice and clean way to migrate from paperclip but none from attachment_fu, because J. Nicklas claims, they're too far a part.

Well here's a little module you can include in your uploader and adapt to your needs.

Any Questions ?


Paul Cook said...

Thanks! Just what I was looking for to help with my move to CarrierWave.

Dan Bernier said...

The only problem I found with this is that when version_name is nil, and filename contains underscores, this code will strip them out: my_pic.png will become mypic.png. The problem is that when version_name is nil, "#{version_name}_" becomes "_", and then it gsub's "_" out of the filename.

Prefacing it all with "return filename if version_name.blank?" fixes it.

hvillero said...

Hi There,
Thank you for that post, however can you tell me how to use after included that into the uploader class?,

Thank you

Anonymous said...

Very useful, thanks!