2017-01-11 2 views
1

У меня есть пользовательский процессор для стилей скрепки: cropper.rb. Хотя он не вызывается и не возвращается NameError (неинициализированная константа Paperclip :: Cropper) ошибка.неинициализированная константа Paperclip :: Cropper

Это обсуждалось здесь: Rails3 and 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 

Библиотека/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 

ответ

0

OK потратил день на то, чтобы реализовать правильную подпапку lib на самом деле paperclip, а не paperclip_processors, хотя Paperclip Git упоминает как действительные, так и автоматически загружаемые.