簡體   English   中英

未初始化的常量Paperclip :: Cropper

[英]uninitialized constant Paperclip::Cropper

我的Paperclip樣式有一個自定義處理器:cropper.rb。 雖然它沒有被調用並返回NameError(未初始化的常量Paperclip :: Cropper)錯誤。

這里已經討論過: Rails3和Paperclip但不久之前。 那是關於Rails 3的。

我在Rails 5下(從Rails 4.x更新)

Profilepic.rb

class Profilepic < ApplicationRecord

  belongs_to :professionnels

  has_attached_file :image, styles: { big: "1200x1200", medium: "400x400", small: "250x250"}
  validates_attachment :image, content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }, size: {less_than: 10.megabytes}

  has_attached_file :finalimage, styles: { medium: "500x500", small: "200x200"}, whiny: false, use_timestamp: false, processors: [:cropper]

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

end

LIB / paperclip_processors / cropper.rb

module Paperclip
  class CustomCropper < Thumbnail
    def initialize(file, options = {}, attachment = nil)
      super
      if target.crop_w && target.crop_x
        @current_geometry.width  = target.crop_w
        @current_geometry.height = target.crop_h
      end
    end

    def target
      @attachment.instance
    end

    def transformation_command
      # call crop processing only if user inputs are there
      if target.crop_w && target.crop_x
        crop_command = [
            "-crop",
            "#{target.crop_w}x" \
            "#{target.crop_h}+" \
            "#{target.crop_x}+" \
            "#{target.crop_y}",
            "+repage"
        ]
        crop_command + super
      else
        super
      end
    end

  end
end

OK花了一天時間才意識到正確的lib子文件夾實際上是paperclip而不是paperclip_processors盡管Paperclip Git確實提到了有效和自動加載。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM