views:

104

answers:

2

I just started using paperclip and have a custom processor. I have put the new processor in the correct location RAILS_ROOT/lib/paperclip_processors But, it does not get loaded.

The reason for not loading, is that Rails.root is nil at the time paperclip is loaded. I've tested this by putting explicit code into the paperclip.rb

puts "What is Rails.root? #{Rails.root}  #{Rails.root.nil?}"

if defined?(Rails.root) && Rails.root
  Dir.glob(File.join(File.expand_path(Rails.root), "lib", "paperclip_processors", "*.rb")).each do |processor|
    require processor
  end
end

Which will print out What is Rails.root true. And the processors are never load.

Is there a fix or work around for this? The work around right now is to just add a require for our processor. but that doesn't seem right.

A: 

I ended up with requireing processors manualy in the job definition file. Have you found any better solution to this issue?

mdrozdziel
Sadly, that is exactly what we have done. I've asked on the Paperclip mailing list and gotten no response there either. Seems like they would fix it at some point in the source code.
christophercotton
I am not sure whats the status of the original paperclip? Looks like there are pretty fresh commints, but the issue tracker on github seems quite dead, with one year old problems without any notice. Have you run into the bug, where objects passed to the processor are sometimes nil? http://groups.google.com/group/paperclip-plugin/browse_frm/thread/c2f5a7ae58fff976/ee5b6b21ef9c9ca6http://github.com/mdrozdziel/paperclip/commit/aa979cbe17fd875d4ee5cf4cf6eff8768a57ebc2
mdrozdziel
+1  A: 

I had to include the paperclip_processors directory

module Trunk
 class Application < Rails::Application

 Paperclip::Railtie.insert

 # Custom directories with classes and modules you want to be autoloadable.
 config.autoload_paths += %W(#{Rails.root}/lib)  
 config.autoload_paths += %W(#{Rails.root}/lib/paperclip_processors)  
 end
end

But I'm still having a problem where it's not loading the class within cropper.

Expected /Users/jspooner/Dropbox/active/local.active.com/rails3/trunk/lib/paperclip_processors/cropper.rb to define Cropper

cropper.rb

module Paperclip
  class Cropper < Thumbnail
    def transformation_command
      if crop_command
        crop_command + super[1..super.length]
      else
        super
      end
    end

    def crop_command
      target = @attachment.instance
      if target.cropping?
        " -crop '#{target.crop_w.to_i}x#{target.crop_h.to_i}+#{target.crop_x.to_i}+#{target.crop_y.to_i}'"
      end
    end
  end
end
jspooner