Rails form submitting POST rather than PATCH

Hello there,

I have a Rails 7.0.4.3 application in the wild and there is one particular user out there who cannot submit the update form.

When he tries he generates the following error:

ActionController::RoutingError: No route matches [POST] /path/to/resource/resource-id

This, of course, is because that request should be a PATCH.

I am able to generate a similar error by deleting the <input type="hidden" name="_method" value="patch" autocomplete="off"> element (using browser devtools) before submitting the form.

I turned on debug logging in production to try to see if the ‘_method’ parameter was actually being sent, but the logs of ‘Parameters:’ do not seem to include ‘_method’ even for users who can submit the form successfully. Does something strip that parameter from logs or something?

I am somewhat at a loss to explain why one particular user and only that user should have this problem. Does anyone have any ideas?

Things that may or may not be relevant:

  • He is using Chrome on some kind of Android phone
  • The form itself has not submit button - I submit it via javascript form.submit()

Try changing that form.submit() to form.requestSubmit(). It’s a subtle difference, but the former is not going to engage the Rails JavaScript helpers while the latter does. I’m not absolutely certain that this is what’s failing for you here, but it may be significant. There is a polyfill for requestSubmit out there as well; it’s needed by certain older versions of WebKit, and that may also be a reason for this behavior.

Walter

Thanks Walter,

I tried changing it to form.requestSubmit(), and since then the user seems to have been able to submit the form. I’m still trying to confirm whether it was this changed that fixed it, or whether they used a different device, but theres a distinct possibility this did the trick!