Flowdock
method

preview

Importance_2
v6.0.0 - Show latest stable - 0 notes - Class: Representable
preview(transformations) public

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.service_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?.

Show source
Register or log in to add new notes.