Thoughts on Technology, Methodology and Programming.

Archive for August, 2007

acts_as_attachment on $^@#$ windows

Posted by Marcus Wyatt on 16 August 2007

Why would you use windows to do this man?

Because I haven’t bought that nice shiny MacBook Pro yet… But enough of that… So I’m building this Rails app that needs to display images. So where do I look first, of course techno-weenie and the great tutorial from Mike Clark on File Upload Fu. So the long and short of this is the following:

I tried to get the local file system upload to work, but firstly I run into problems to install the ImageScience library. I not only using window operating system, but I’m running XP x64. So I even had issues finding make/nmake for 64 bit. So I decided to use RMagick.

Next, I installed RMagick and with a tweak to the rmagick_processor.rb file and by commenting the validates_as_attachment in my model class I was able to create the images on the file system. I’ve added the bang(!) operator to line 8. i.e. image.resize!(cols, rows)

   1: # Performs the actual resizing operation for a thumbnail
   2: def resize_image(img, size)
   3:   size = size.first if size.is_a?(Array) && size.length == 1 && !size.first.is_a?(Fixnum)
   4:   if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
   5:     size = [size, size] if size.is_a?(Fixnum)
   6:     img.thumbnail!(*size)
   7:   else
   8:     img.change_geometry(size.to_s) { |cols, rows, image| image.resize!(cols, rows) }
   9:   end
  10:   self.temp_path = write_to_temp_file(img.to_blob)
  11: end

Now I was on the hunt to solve the validation issue “Size is not included in the list”. Firstly I found this and this solutions, but neither solved the issue. Then I found this solution and great my issues is solved. Whoa!

Then I tried to change my storage to Amazon S3 and although the images are resized and uploaded, there was something wrong with them. Some images where mangled and other had no image. So now I was worried!

It turns out that there is a problem with the tempfile.rb within Ruby. So I found this solution and now I have a working solution. Awesome!

Damn windows…

Posted in RoR | Leave a Comment »