instance method
preview
Ruby on Rails 7.2.3
Since v5.2.8.1Signature
preview(transformations)
Returns an ActiveStorage::Preview instance with the set of transformations provided. A preview is an image generated from a non-image blob. Active Storage comes with built-in previewers for videos and PDF documents. The video previewer extracts the first frame from a video and the PDF previewer extracts the first page from a PDF document.
blob.preview(resize_to_limit: [100, 100]).processed.url
Avoid processing previews synchronously in views. Instead, link to a controller action that processes them on demand. Active Storage provides one, but you may want to create your own (for example, if you need authentication). Here’s how to use the built-in version:
<%= image_tag video.preview(resize_to_limit: [100, 100]) %>
This method raises ActiveStorage::UnpreviewableError if no previewer accepts the receiving blob. To determine whether a blob is accepted by any previewer, call ActiveStorage::Blob#previewable?.
Parameters
-
transformationsreq
Source
# File activestorage/app/models/active_storage/blob/representable.rb, line 129
def preview(transformations)
if previewable?
ActiveStorage::Preview.new(self, transformations)
else
raise ActiveStorage::UnpreviewableError
end
end
Defined in activestorage/app/models/active_storage/blob/representable.rb line 129
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveStorage::Blob::Representable