Rails form submission with a long-running validation

Rails 6.1, Stimulus 2 + Turbo.

I have a scenario where a user is presented with a form to update their account. When they submit the update, there is a potentially long-running process to a third-party API spawned off in ActiveJob. One of these API calls could generate an error, which I’d want to send back to the user to correct. I don’t have a way to validate the error locally, it must go to the API to find out if it’s good or not.

Right now, I feel like the form submission should complete successfully, return a view that’s a progress indicator of some kind, and use a turbo_stream to display the edit form if an error comes up, but I’m not even sure exactly how I’d do that.

Is there an easier way? If not, how would I indicate in a turbo_stream that I need to display the edit form with errors from the ActiveJob process?

1 Like

Theres a couple of ways you could approach this, unfortunately doing so in a forum like this would be hard. If you want to come over to the StimulusReflex discord, we’d be happy to discuss some options, pros / cons of each, and see if we can figure out something!

(Apologies if this isnt okay, but heres the link to the SR discord)

1 Like

I solved this in a somewhat roundabout way, adding an “updating” state to the record, saving it normally, and then updating the status back to “ready” in the background job, using the streaming update stuff to alter the UI. Works a charm.