简体   繁体   English

未初始化的常量Paperclip :: Cropper

[英]uninitialized constant Paperclip::Cropper

I have a custom processor for my Paperclip styles: cropper.rb. 我的Paperclip样式有一个自定义处理器:cropper.rb。 Though it is not called and return NameError (uninitialized constant Paperclip::Cropper) error. 虽然它没有被调用并返回NameError(未初始化的常量Paperclip :: Cropper)错误。

It has been discussed here : Rails3 and Paperclip but a while ago. 这里已经讨论过: Rails3和Paperclip但不久之前。 It was concerning Rails 3 back then. 那是关于Rails 3的。

I am under Rails 5 (update from Rails 4.x) 我在Rails 5下(从Rails 4.x更新)

Profilepic.rb 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 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.

相关问题 未初始化的常数Mongoid :: Paperclip - uninitialized constant Mongoid::Paperclip Rails回形针水印“未初始化的常量回形针” - Rails paperclip watermark “uninitialized constant Paperclip” 未初始化的常量Paperclip :: paperclip-ffmpeg错误 - uninitialized constant Paperclip::Error with paperclip-ffmpeg 使用Unicorn进行生产中的回形针:未初始化的常量回形针(NameError) - Paperclip in Production with Unicorn: uninitialized constant Paperclip (NameError) Paperclip,未初始化的常量Paperclip :: Storage :: Fog :: Excon - Paperclip, uninitialized constant Paperclip::Storage::Fog::Excon 回形针错误:未初始化的常量Paperclip(NameError) - Paperclip Error: uninitialized constant Paperclip (NameError) 未初始化的常量Paperclip :: Storage :: S3 :: Aws - uninitialized constant Paperclip::Storage::S3::Aws Rails 3-回形针:未初始化的常量ActionDispatch :: Request :: UploadedFile - Rails 3 - Paperclip: uninitialized constant ActionDispatch::Request::UploadedFile Paperclip aws-sdk错误:未初始化的常量 - Paperclip aws-sdk error: uninitialized constant Heroku上的Rails 4中的回形针NameError(未初始化的常量AWS :: S3 :: Errors) - Paperclip NameError (uninitialized constant AWS::S3::Errors) in Rails 4 on heroku
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM