[Feature] Retain upload after form redisplay with Active Storage

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[Feature] Retain upload after form redisplay with Active Storage

Chris Seelus

When uploading files with Active Storage, after the form was submitted and the form gets redisplayed, for example when the validation for the model that form is based on fails for some reason, the file is gone.

As far is I know, currently there is no easy way to cache or retain it between form redisplays. Has anyone here implemented something like that on their project with Active Storage yet?

Shrine has a great Plugin for that purpose:

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.

Basically one just has to add a hidden field to a form, which stores the upload on form redisplays:

form.hidden_field :image, value: @model.cached_image_data

Implementing something similar would be a worthwhile feature to try and contribute back to Rails or is there anything that prevents this?

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.