Skip to main content
Ask A Question
Notifications
You’re not receiving notifications from this thread.
Subscribe

Persist file info after rails validation error

General • Asked by Alex Deering

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?


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,353+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.