Shrine

Defining and generating derivatives for existing records

Assume I’ve been using shrine for Upload record, and it has a field image where the uploaded image is attached against (basically we store metadata in image_data).

Whenever an Upload record is created with the attached image, we generate the derivatives small and large. We now have a bunch of Uploads lying around, all having small and large derivatives.

We now want to introduce a new derivative - medium. We can define this and the derivative will be generated for newer Uploads - but how do we ensure existing Uploads have them too?

Apologies in advance if there’s an obvious solution to this already - I searched here and in the documentation but didn’t find any.

Does this guide help?

Yes! Sorry I didn’t find it earlier. I googled for shrine gem derivatives and landed on this first result - Derivatives · Shrine

Thinking that was the official documentation, and there’s nothing else, and then I hopped onto here.

You can think of the derivatives plugin documentation as more of an API reference, and the guides section as more of “how-to” tutorials.

1 Like