Active Storage: Best practice to retain/cache uploaded file when form redisplays

百般思念 提交于 2019-11-29 18:33:56

问题


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.


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!