Make attachment_fu work with Rails 1.1.6

I was using acts_as_attachment plugin for file upload and I wanted to get the files to Amazon S3. Unfortunately acts_as_attachment does not do that and attachment_fu does (both of these great plugins are written by Rick Olsen) and attchment_fu needs Rails 1.2 and higher. I have a limitation of using Rails 1.1.6.  So made attachment_fu work with Rails 1.1.6. Not a whole lot of changes , should take less that 3 mins. So this is what you  do

         base.alias_method_chain :process_attachment, :processing

with

base.send :alias_method, :process_attachment_without_processing, :process_attachment
base.send :alias_method, :process_attachment, :process_attachment_with_processing

(The reason it needed Rails 1.2 in first place because of  base.alias_method_chain call which is introduced in Rails 1.2. So It was just a matter of replacing that with the Rails 1.1.6 equivalent). Similarly you can go do the same above change to other 2 processors as well (image_science and mini_magick)

        def find_or_initialize_thumbnail(file_name_suffix)
          respond_to?(:parent_id) ?
            thumbnail_class.find_or_initialize_by_thumbnail_and_parent_id(file_name_suffix.to_s, id) :
            thumbnail_class.find_or_initialize_by_thumbnail(file_name_suffix.to_s)
        end

with

        def find_or_initialize_thumbnail(file_name_suffix)
          respond_to?(:parent_id) ?
            thumbnail_class.find_by_thumbnail_and_parent_id(file_name_suffix.to_s, id) || 
            thumbnail_class.new(:thumbnail=>file_name_suffix.to_s, :parent_id=>id) : 
            thumbnail_class.new(:thumbnail=>file_name_suffix.to_s)
        end

Thats it  you should be flyig with this change on Rails 1.1.6.

Comments

One Response to “Make attachment_fu work with Rails 1.1.6”

  1. Saving Someone’s Day » Make paginating_find work with Rails 1.1.6 on January 17th, 2008 4:01 pm

    […] This technique works with any alias_method_chain backward compatibility to older version of Rails. I have posted similar post for attachment_fu make it work with Rails 1.1.6 here […]

Leave a Reply