如何实现Image_processing后端管道?

时间:2019-10-14 21:45:11

标签: ruby-on-rails

如果我尝试在视图中尝试以下方法之一,那么它将起作用:

    <%= image_tag upload.variant(resize_to_limit: [75, 75]) %>
    <%= image_tag upload.variant(resize_to_fill: [300, 200]) %>

但是当我从模型实现为具有更多配置的文档时,例如:

models / todo.rb

require "image_processing/mini_magick"


class Todo < ApplicationRecord
    has_many_attached :uploads


    def thumb_magick image
      pipeline = ImageProcessing::MiniMagick.source(image)
      result = pipeline.resize_to_fill(400, 400)
    end

end

视图/todos/show.html.erb

 <%= image_tag(@todo.thumb_magick(upload)) %>

然后在视图中弹出此错误消息:

Can't resolve image into URL: undefined method `persisted?' for #<ImageProcessing::Builder:0x00007fd2602b9320>

application.rb

config.active_storage.variant_processor

配置:

  • 导轨6.0.0
  • Ruby 2.6.5

宝石文件

  • 图像处理(1.9.1)
  • mini_magick(> = 4.9.5,<5)

Github:

image_processing config to mini_magick

0 个答案:

没有答案