Paperclip processors not loading in Rails 3.0.0rc

I just started using paperclip and have my own processor. I put the new processor in the right place RAILS_ROOT/lib/paperclip_processorsBut it does not load.

The reason for not loading is that it Rails.rootis zero at the time of loading paperclip. I tested this by adding explicit code topaperclip.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

Will be printed What is Rails.root true. And processors never load.

Is there a fix or work for this? Now, the work around is simply to add a requirement for our processor. but that does not seem right. Here is the work (our processor does tar'ing), in the model that will use the processor, you just need to go to the top:

require "#{Rails.root}/lib/paperclip_processors/tar.rb"

class Ad < ActiveRecord::Base
  has_attached_file :adzip, 
                :styles         => { :targzip => {:processors => [:tar], :format => 'tgz'} }
end
+3
1

paperclip_processors

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

, .

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
+4

Source: https://habr.com/ru/post/1759673/


All Articles