When uploading files with Active Storage, when a file is finished uploading and the form gets redisplayed, for example when the validation for that form fails for some reason, the file is gone.
Is there a way to cache or retain it between form redisplays? Shrine has a nice Plugin for that purpose, I'm looking for something similar for Active Storage.
Here's a solution to make ActiveStorage files persist on form redisplay:
f.hidden_field :image, value: f.object.image.signed_id if f.object.image.attached?
f.file_field :image
来源:https://stackoverflow.com/questions/50360307/active-storage-best-practice-to-retain-cache-uploaded-file-when-form-redisplays