- If an attachment is
representable? we render the attachment as an image tag
representable? can be true for the following types if their related tools are installed on the system
- PDF
- If the system has
poppler installed -> PopplerPDFPreviewer or
- If the system has
muPDF installed -> MuPDFPreviewer
- Video
- If the system has
ffmpeg installed -> VideoPreviewer
- If either
poppler or muPDF is installed(Or even for video), we need to create the image_tag as given below..
blob.preview(resize_to_limit: [100, 100])
For more details => https://api.rubyonrails.org/v7.0.8/classes/ActiveStorage/Preview.html & https://api.rubyonrails.org/v7.0.8/classes/ActiveStorage/Blob/Representable.html
Proposed change
if value.try(:representable?)
if value.try(:variable?)
image_tag( @variant.nil? ? value : value.variant(@variant))
else
image_tag(value.blob.preview(resize_to_limit: [100, 100]))
end
elsif value.try(:attached?)
link_to value.blob.filename, rails_blob_path(value, disposition: :attachment)
else
""
end
Example using Hunter & Co. app

representable?we render the attachment as an image tagrepresentable?can be true for the following types if their related tools are installed on the systempopplerinstalled ->PopplerPDFPreviewerormuPDFinstalled ->MuPDFPreviewerffmpeginstalled ->VideoPreviewerpopplerormuPDFis installed(Or even for video), we need to create theimage_tagas given below..For more details => https://api.rubyonrails.org/v7.0.8/classes/ActiveStorage/Preview.html & https://api.rubyonrails.org/v7.0.8/classes/ActiveStorage/Blob/Representable.html
Proposed change
Example using Hunter & Co. app