您好我正在使用带有Rails的MongoDB,因为我使用paperclip和Jcrop进行图像裁剪。 但是我收到了这个错误。请帮我。
undefined method `sub' for #<Array:0x007fcdb436ad38>
crop_command + super.sub(/ -crop \S+/, '')
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
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
答案 0 :(得分:1)
您对super
的调用会返回一个数组,而不是字符串。但是#sub
是在字符串上定义的方法。
我猜你可能想做:
crop_command + super.first.sub(/ -crop \S+/, '')