Turbo-friendly 422 responses for invalid forms

3555
0

In a Turbo app, returning the right HTTP status is not optional—it controls how Turbo treats the response. For invalid form submissions, return 422 Unprocessable Entity and render the form with errors. If you mistakenly return 200, Turbo may treat it like a successful navigation, which can break back button behavior and confuse users. I use render ..., status: :unprocessable_entity consistently for both turbo streams and HTML. This is especially important in modals: if validation fails, you want the modal content to update, not the page to navigate away. Once the status codes are correct, everything else (Stimulus controllers re-connecting, error highlighting) tends to work naturally.