我正在尝试预览我上传的PDF文件和图像文件:
class Document < ApplicationRecord
belongs_to :resourceable,:polymorphic => true
has_one_attached :file
end
我尝试使用.preview和.representation方法将上传的图像或pdf的预览显示为缩略图。
- 使用preview(),导致以下错误:
@document.file.preview(resize_to_limit: [100,100])
activeStorage::UnpreviewableError: activeStorage::UnpreviewableError
- 使用representation(),image_tag无法从activeStorage :: Variant对象解析图像URL,从而导致以下错误:
>>> image_tag(@document.file.representation(resize: '500x500'))
ArgumentError: Can't resolve image into URL: undefined method `to_model' for #<activeStorage::Variant:0x00007fe39e809768>
document.file.representable?
和document.file.previewable?
在某些文档中。想知道这些方法做什么?有时我可以表示为true,但可以预览为false。