3

According to various sources, the way to fail form validation in Rails 7 is to respond with status 422 unprocessable entity. However, in my case, this causes Turbo to issue yet another GET request, which is unlikely to be the desired outcome.

The log looks as follows:

Started POST "/users/new" for 127.0.0.1 at 2022-06-16 17:27:48 +0200
...
TRANSACTION (0.3ms)  ROLLBACK
...
Rendered html template (Duration: 0.0ms | Allocations: 4)
Completed 422 Unprocessable Entity in 133ms (Views: 1.2ms | ActiveRecord: 10.9ms | Allocations: 54437)

Started GET "/users/new" for 127.0.0.1 at 2022-06-16 17:27:48 +0200
...

So, from a Rails perspective, everything seems normal, as the server responds with the required 422 status code. When inspecting the response in the browser, I see the form with the error messages. However, for some reason, Turbo then issues a redirect to /users/new instead of letting the browser display the form containing the errors.

UPDATE: The form is generated using simple_form_for.

How can I find out why Turbo reloads the page?

Best, Kalsan

Kalsan
  • 822
  • 1
  • 8
  • 19
  • Hi @Kalsan - did you find a solution to this issue? – Dan Laffan Jun 23 '22 at 21:40
  • Unfortunately not. Are you also affected by this? I've been feeling like I'm the only person on earch/Google to have this problem for the last 2 weeks... – Kalsan Jun 24 '22 at 08:43

1 Answers1

1

This happens when the server responds with a partial to a form post. Returning a complete site, including <html> etc. solves the problem.

Kalsan
  • 822
  • 1
  • 8
  • 19