我的 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,所以我正在寻找一些关于如何处理这个问题的建议。