嗨,我正在使用MongoDB和Rails,因为我正在使用回形针和Jcrop进行图像裁剪。但是我收到此错误。请帮助我。
undefined method `sub' for #<Array:0x007fcdb436ad38>
crop_command + super.sub(/ -crop S+/, '')
模型.rb
as_mongoid_attached_file :doctor_avatar,
:styles => { :small => "100x100#", :large => "500x500>" },
:processors => [:cropper]
attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
after_update :reprocess_avatar, :if => :cropping?
def cropping?
!crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank?
end
private
def reprocess_avatar
doctor_avatar.reprocess!
end
Cropper.rb
module Paperclip
class Cropper < Thumbnail
def transformation_command
if crop_command
crop_command + super.first.sub(/ -crop S+/, '')
else
super
end
end
def crop_command
target = @attachment.instance
if target.cropping?
" -crop '#{target.crop_w.to_i}x#{target.crop_h.to_i}+#{target.crop_x.to_i}+#{target.crop_y.to_i}'"
end
end
end
对 super
的调用返回一个数组,而不是一个字符串。但是#sub
是在字符串上定义的方法。
我猜你可能想这样做:
crop_command + super.first.sub(/ -crop S+/, '')