1

我的 rails 4 应用程序在回形针重新处理方法方面存在一些问题。我有一个自定义 Cropper 模块:

module Paperclip
  class Cropper < Thumbnail
    def transformation_command
      if crop_command
        crop_command + super.sub(/ -crop \S+/, '')
      else
        super
      end
    end

    def crop_command
      target = @attachment.instance
      if target.cropping?
        ratio = target.avatar_geometry(:original).width  / target.avatar_geometry(:large).width
        ["-crop", "#{(target.crop_w.to_i*ratio).round}x#{(target.crop_h.to_i*ratio).round}+#{(target.crop_x.to_i*ratio).round}+#{(target.crop_y.to_i*ratio).round}"]
      end
    end
  end
end

我有一些用于crop_x、crop_y、crop_w、crop_h的attr_accessors。

我遇到了crop_x、y、w和h在到达cropper类时可用的问题。即使在控制器中(在更新方法期间)这些元素不为零,这些元素也始终为零。

我相信这与他们有关 attr_accessors,所以我正在寻找一些关于如何处理这个问题的建议。

4

1 回答 1

0

在处理更新的控制器中,您是否包含 :crop_x、:crop_y、:crop_w、:crop_h 作为允许的参数?

你应该有这样的东西:

params.require(:model).permit(:attribute1, :attribute2, :crop_x, :crop_y, :crop_w, :crop_h)
于 2013-09-18T15:48:00.470 回答