ruby-on-railsrubyruby-on-rails-3attachment-furails-3-upgrade

Has anyone been able to get attachment_fu to work with rails 3?


I have a rails application that is being upgraded from Rails 2.3.5 to Rails 3. It uses attachment_fu for file uploads. We're trying to do this conversion without making DB changes, so I'd like to avoid changing to paperclip or carrierwave at this time.

Has anyone succeeded in using attachment_fu with Rails 3 and Ruby 1.9.2? We're using the most recent version of attachment_fu that claims to be ok for rails 3 and ruby 1.9.2, but getting 'TypeError (can't convert nil into Integer):' on any forms that include a file upload.

All the answers to previous questions seem to be 'just switch to paperclip or carrierwave' as in: Attachment_fu or Paperclip for Rails3 or TypeError (can't convert nil into Integer):

Thanks!


Solution

  • I made the following changes and it worked

    attachment_fu.rb

    def temp_path
      p = temp_paths.first
      if p.is_a?(ActionDispatch::Http::UploadedFile) # Rails 3.0.3 compatability fix
        p.tempfile.path
      else
        p.respond_to?(:path) ? p.path : p.to_s
      end
    end
    

    I also changed returning filename.strip do |name| to filename.strip.tap do |name|

    init.rb

    def make_tmpname(basename, n)
      ext = nil
      n ||= 0
      sprintf("%s%d-%d%s", basename.to_s.gsub(/\.\w+$/) { |s| ext = s; '' }, $$, n, ext)
    end
    

    I made a fork on github with this changes https://github.com/debprado/attachment_fu