【发布时间】:2013-09-19 00:05:55
【问题描述】:
我的 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。
我遇到了一个问题,即当它到达cropper 类时,crop_x、y、w 和 h 可用。即使在控制器中(在更新方法期间)这些元素不是 nil,这些元素也始终为 nil。
我相信这与 attr_accessors 有关,所以我正在寻找一些关于如何处理这个问题的建议。
【问题讨论】:
标签: ruby-on-rails ruby paperclip