Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails3 and Paperclip

I have migrated my application from rails 2.3 to rails3 and i have a problem with paperclip. I saw there was a branch for rails3 on paperclip git.

So I added "gem 'paperclip', :git => 'git://github.com/thoughtbot/paperclip.git', :branch => 'rails3'" into the Gemfile and launch the command bundle install.

Once paperclip installed, the upload worked fine but not the styles. I saw a hack to fix it.

# in lib/paperclip/attachment.rb at line 293
def callback which #:nodoc:
  # replace this line...
  # instance.run_callbacks(which, @queued_for_write){|result,obj| result == false }
  # with this:
  instance.run_callbacks(which, @queued_for_write)
end

The styles are ok after that, but i'm not able to active the processor. My code is :

has_attached_file                 :image,
                                  :default_url => "/images/nopicture.jpg",
                                  :styles => { :large   => "800x600>",
                                               :cropped => Proc.new { |instance| "#{instance.width}x#{instance.height}>" },
                                                :crop    => "300x300>" },
                                   :processors => [:cropper]

My processor is located in RAILS_APP/lib/paperclip_processors/cropper.rb and contains :

module Paperclip
  class Cropper < Thumbnail
    def transformation_command
      if crop_command  and !skip_crop?
        crop_command + super.sub(/ -crop \S+/, '')
       else
         super
       end
    end

   def crop_command
      target = @attachment.instance
      trans = "";
      trans << " -crop #{target.crop_w}x#{target.crop_h}+#{target.crop_x}+#{target.crop_y}" if target.cropping?
      trans << " -resize \"#{target.width}x#{target.height}\""
      trans
   end

   def skip_crop?
     ["800x600>", "300x300>"].include?(@target_geometry.to_s)
   end
 end
end

My problem is that i got this error message : uninitialized constant Paperclip::Cropper The cropped processor is not loaded.

Is anybody has an idea to fix that ?

For information my application works fine on rails 2.3.4.

like image 443
Arkan Avatar asked Feb 26 '10 11:02

Arkan


People also ask

What is Paperclip in Rails?

Paperclip is an easy file attachment library for Rails Applications. Attached files are saved to the file system, database or cloud and referenced in the browser by an easily understandable specification.

How do you use a paperclip in rails?

Setting Up PaperclipTo set up Paperclip, first we need to install the ImageMagick dependency. Paperclip uses ImageMagick to resize images after upload. If you are using another system, you can get download and install instructions from the ImageMagick website. Run bundle install to finish it up.


2 Answers

I have the same problem. Seems like paperclip processors are not loaded in rails 3. Until someone fix it, I hacked the problem moving the cropper.rb file inside /config/initializers

like image 133
Ferdy Avatar answered Oct 11 '22 07:10

Ferdy


Restart server, worked for me :)

like image 44
tomi Avatar answered Oct 11 '22 07:10

tomi