Archive

Archive for October, 2009

Converting attachment_fu to Paperclip

October 1st, 2009 mindtonic No comments

I am making the transition from attachment_fu to paperclip on a very large project of mine. I wrote the following method, inside of my old attachment_fu model ItemImage to do the work. I wrote it to run from inside the rails console. It gives handy messages out letting you know what happened. In my case you run:

$ script/console
>> ItemImage::convert_fu
def self.convert_fu
  for item in Item.all
    # has an image
    if item.item_image
      # the image exists
      filename = "public" + item.item_image.public_filename
      if File::exists?(filename)
        image = File.open(filename)
        item.image = image
        item.save
        puts "#{item.name} Image Converted"
      else
        puts "====> #{item.name} Image could not be found"
      end
    else
      puts "#{item.name} has no image"
    end
  end
end

Reference: http://thewebfellas.com/blog/2008/11/2/goodbye-attachment_fu-hello-paperclip

Categories: Gems, Ruby On Rails Tags: ,