我使用 Rails 和 Paperclip gem 来上传图像。我不知道它是什么时候发生的,因为我现在才注意到,但在最近的某个时刻,他们一定改变了 Geometry 类,因为它现在抛出了一个错误。我正在使用回形针 3.3.1
我曾经使用过:
Paperclip::Geometry.from_file(photo.path(style))
获取照片几何形状,但现在当我这样做时,我得到:
undefined method `to_file' for #<Paperclip::Attachment:0x007feba0009fb8>
我一直在寻找一些线索的来源,但这不是我的强项,而且我没有发现任何太有启发性的内容。
任何人
最佳答案
我使用的是 3.3.1,并将其放在我的 photo.rb 中,以便在保存之前更新我的照片记录。
def do_before_save
temp = self.image.queued_for_write[:original]
unless temp.nil?
geo = Paperclip::Geometry.from_file(temp)
self.image_width = geo.width
self.image_height = geo.height
end
end
关于ruby-on-rails - 回形针几何类不再有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13485887/