2

I am following Episode: 182-cropping-images for cropping user profile image.

AR relation is User has one Profile Image: In User model:

 has_one :profile_image, :as => :imageable, :class_name => 'ProfileImage', :dependent => :destroy

In ProfileImage Model:

 class ProfileImage < Image
   has_attached_file :data, :styles => {
  :large => "160x160>",
  :grid => "114x114>",
  :medium => "80x80>",
  :list => "60x60>",
  :square => "32x32!",
  :tiny => "20x20!",
  :icon => "16x16!"
}, :processors => [:cropper]

attr_accessor :crop_x, :crop_y, :crop_w, :crop_h


def cropping?
  !crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank?
end

def avatar_geometry(style = :original)
  @geometry ||= {}
  @geometry[style] ||= Paperclip::Geometry.from_file(data.path(style))
end

In lib/paperclip_processors/cropper.rb lib:

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

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

and all other things like Episode: 182-cropping-images with solution Now, I am getting error:

 NoMethodError Exception: super: no superclass method  'transformation_command' for Paperclip::Cropper

in line:

crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ')

If I remove, + super.join(' ').sub(/ -crop \S+/, '').split(' ')

It crops all images style into same height width. Please guide.

Community
  • 1
  • 1
Manish Shrivastava
  • 30,617
  • 13
  • 97
  • 101
  • Everything looks correct. Have you consider checking what `super` might return/ or working, before `if crop_command` inside `def transformation_command` method? – Surya May 23 '14 at 11:13
  • @Surya, `crop_command` return proper command as it should. But `super` return error as in title. I checked it via debugger at lib/paperclip_processors/cropper.rb lib: just before `crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ')` – Manish Shrivastava May 23 '14 at 11:28
  • 1
    Weird, I checked Paperclip's Thumbnail class and `transformation_command ` exists there. That's why I asked if `super` returns the array before the `if crop_command ` line in `transformation_command` method. – Surya May 23 '14 at 11:34
  • 1
    I'll try to setup paperclip on my machine this weekend. Let's see if I could get this working. :) – Surya May 23 '14 at 12:58
  • @Surya, I will be bless if you could share your code on weekend. I am trying this since a week. pak gya yar!! – Manish Shrivastava May 23 '14 at 13:06
  • hahahaha.. happens. Share your Gemfile or related gems' versions, better if you could share your own code so that'd save my setup time. – Surya May 23 '14 at 13:07
  • @Surya, gemfile has so much kachra. But Brief is: `Ruby 2.1.1`, `Rails 3.2.15`, `paperclip (3.5.2)`. thanks in advance!! – Manish Shrivastava May 23 '14 at 13:13
  • Are you sure that the `Thumbnail` is in your cropper.rb is referencing the correct `Thumbnail` class? Maybe you have global `Thumbnail` class in your app (do you maybe have a table in your database called `Thumbnail`?) or another gem which uses this class name... – nemesv May 23 '14 at 14:17
  • 1
    This error can only happen (based on the source of the `Paperclip:: Thumbnail#transformation_command` that your cropper.rb i gets loaded **after** your other `Thumbnail` gets loaded but **before** the Paperclip gem loads. So check your load path/order and make sure that you derive from the correct class. You can test this out with writing: `class Cropper < Paperclip::Thumbnail` because if my theory is correct you should get now an uninitialized constant error. – nemesv May 23 '14 at 14:42
  • @nemesv thanks for your response. well, I don't have any other thumbnails in my app directory. It should reference Paperclip thumbnail class. I will try second reply of yours tomorrow. Thanks for vital suggestions. – Manish Shrivastava May 25 '14 at 06:06

1 Answers1

1

Only looking at the error you're getting...

My guess is that this line is falling through to the else

if crop_command
  crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ')
else
  super
end

And your Thumbnail class isn't setup properly, so when you call super its looking for Thumbnail#transformation_command which doesn't exist.

Looking at the docs, this method relies on ImageMagick being installed and setup correctly.

have you followed this step?

engineerDave
  • 3,887
  • 26
  • 28