Ruby on rails NoMethodError异常:super:无超类方法';转换命令';用于回形针::裁剪器
我下面的裁剪用户配置文件图像 AR关系是指用户有一个配置文件图像: 在用户模型中:Ruby on rails NoMethodError异常:super:无超类方法';转换命令';用于回形针::裁剪器,ruby-on-rails,imagemagick,Ruby On Rails,Imagemagick,我下面的裁剪用户配置文件图像 AR关系是指用户有一个配置文件图像: 在用户模型中: has_one :profile_image, :as => :imageable, :class_name => 'ProfileImage', :dependent => :destroy 在ProfileImage模型中: class ProfileImage < Image has_attached_file :data, :styles => { :larg
has_one :profile_image, :as => :imageable, :class_name => 'ProfileImage', :dependent => :destroy
在ProfileImage模型中:
class ProfileImage < Image
has_attached_file :data, :styles => {
:large => "160x160>",
:grid => "114x114>",
:medium => "80x80>",
:list => "60x60>",
:square => "32x32!",
:tiny => "20x20!",
:icon => "16x16!"
}, :processors => [:cropper]
attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
def cropping?
!crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank?
end
def avatar_geometry(style = :original)
@geometry ||= {}
@geometry[style] ||= Paperclip::Geometry.from_file(data.path(style))
end
一致:
crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ')
如果我删除,+super.join(“”).sub(/-crop\S+/,“”).split(“”)
它将所有图像样式裁剪为相同的高度和宽度。请引导。仅查看您得到的错误 我猜这条线会一直延伸到另一条
if crop_command
crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ')
else
super
end
而且您的缩略图类设置不正确,因此,当您调用super时,它会使用查找缩略图#转换(transformation)命令,但该命令不存在
查看文档,此方法依赖于正确安装和设置
你注意到这个了吗 一切看起来都是正确的。您是否考虑过在<代码>之前检查“<代码>超级< /代码>可能返回/工作>,如果CROPH命令内<代码> DEF TrimeStudio命令方法?@ SURYA,<代码> CROPH命令< /代码>应返回正确的命令。但是
super
返回标题中的错误。我通过lib/paperclip\u processors/croper.rb lib上的调试器检查了它:就在cropu命令+super.join(“”).sub(/-crops\S+/,“”).split(“”)之前,我检查了paperclip的缩略图类,并且transformation\u命令存在于那里。这就是为什么我问super
是否在transformation\u命令
方法中的if crop\u命令
行之前返回数组。这个周末我将尝试在我的机器上设置回形针。让我们看看我是否能让它工作起来。:)这种错误只会发生(根据回形针::Thumbnail#transformation_命令的源代码,在加载其他缩略图
后,但在加载回形针gem之前加载croper.rb i。因此,请检查加载路径/顺序,并确保从正确的类派生。您可以通过编写:类croper来测试这一点因为如果我的理论是正确的,你现在应该得到一个未初始化的常量错误。
crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ')
if crop_command
crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ')
else
super
end