I have made a Rails edit form, which works fine.
Looking into the developer tools I have seen that the HTTP method is POST.
Actually I would have expected that it sets the new form to POST and the edit form (shown in the screenshot) to PUT or PATCH.
How is it possible that the correct update action is invoked?
When the method is POST, then I would expect the create action to become invoked, according to the defined routes.
On the terminal a PATCH request is shown, when the edit form is submitted:
Started PATCH "/projects/4" for ::1 at 2025-07-21 12:35:58 +0200
Processing by ProjectsController#update as TURBO_STREAM
Somewhere in-between submit and invocation of the update action something must happen.
You're absolutely right. The magic happens in Rack::MethodOverride.
Browsers do not consistently support request methods other than POST or GET when posting forms. Even when sending XHR requests the support has historically been a a bit spotty.
However Rack (the unsung hero that Rails sits on top of) and the Rails form helpers use a really simple trick to fake the additional set of HTTP verbs (PUT, PATCH, DELETE).
If you look at the request body you'll see a parameter called _method
which is created from a hidden input.
When a POST request goes through the middleware with a valid value in _method
this will override the original HTTP method in the request object that is passed down the stack until it reaches your Rails app.
So to your Rails app there really is almost no difference between this request and a request that was actually sent with a PATCH via for example cURL.