paperclip error while reporcessing after rails 3 upgrade

不想你离开。 提交于 2019-11-29 02:36:30

Hereis my working file:

module Paperclip
  class Cropper < Thumbnail
    def transformation_command
      if crop_command
        crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ') # super returns     an array like this: ["-resize", "100x", "-crop", "100x100+0+0", "+repage"]
      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

Just as an addendum to the accepted answer (assuming you're following Ryan Bates' Railscast), you'll need to remove the following lines from your model:

after_update :reprocess_avatar, :if => :cropping?

def reprocess_avatar
  avatar.reprocess!
end

This will cause an infinite loop. You then just need to move the logic to the update action in the controller by adding something like this:

if @user.cropping?
  @user.avatar.reprocess!
end

I got hung up on this for a while, so thought I'd share.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!