Im working on my main form and have some form validations and running into an issue with a new form not maintaining the image upload after a validation error reloads the page. Here is my form-group for the image upload:
<div class="form-group"> <%= form.label :image, "Recipe Photo" %> <div class="flex flex-row"> <div class="w-full"> <% if form.object.image.attached? %> <%= image_tag form.object.image, class: "w-full border rounded-lg self-center" %> <% end %> </div> </div> <%= form.file_field :image, direct_upload: true, class: "form-control" %> </div>
Because I'm using direct upload the image gets uploaded and still exists after the reload and displays the image with the image_tag in the above code. But when the form is resubmitted the connection in the active_storage tables isnt maintained. Is there a hidden field or something i can put to ensure it gets sent as a param the next time the form is submitted?
Join 31,353+ developers who get early access to new screencasts, articles, guides, updates, and more.