Redirect After PATCH Request

Hi All,

I’m creating following link

link_to 'Action', url, data: { turbo_frame: '_top', turbo_method: :patch }

When user clicks - it correctly sends PATCH request to server where it is handled by controller and controller responds with 302 and new “Location”.

However, browser then sends a request to new “Location” but again with PATCH method.

If I change request to POST - it works correctly and browser follows to new “Location” with GET method.

Have you seen something like this?

Hey Rience,

You need to redirect with a 303 response: Turbo Handbook

Thank you @mrhead - that was it!

I’m still unsure why POST works but PATCH does not. Maybe it could be made clearer in docs?

This isn’t turbo specific, but rather XHR request other than GET or POST.

If you are using XHR requests other than GET or POST and redirecting after the request then some browsers will follow the redirect using the original request method. This may lead to undesirable behavior such as a double DELETE. To work around this you can return a 303 See Other status code which will be followed using a GET request.

see: ActionController::Redirecting