module Shrine::Plugins::CachedAttachmentData

  1. lib/shrine/plugins/cached_attachment_data.rb

The cached_attachment_data plugin adds the ability to retain the cached file across form redisplays, which means the file doesn't have to be reuploaded in case of validation errors.

plugin :cached_attachment_data

The plugin adds #cached_<attachment>_data to the model, which returns the cached file as JSON, and should be used to set the value of the hidden form field.

@user.cached_avatar_data #=> '{"id":"38k25.jpg","storage":"cache","metadata":{...}}'

This method delegates to Attacher#read_cached:

attacher.read_cached #=> '{"id":"38k25.jpg","storage":"cache","metadata":{...}}'