TIL: Rails 7 non-GET links
2022-11-13 00:00:00 +0000 UTCThe Devise default sign out action is triggered by this request DELETE /users/sign_out
. Links, by default, always issue a GET
request.
In Rails 7, the incantation to render a link which triggers a DELETE
request is:
link_to "Sign out", destroy_user_session_path, data: { turbo_method: "DELETE" }
However, the Rails guide also suggests the use of button_to
over link_to
when invoking non-GET
requests for accessibility reasons:
button_to "Sign Out", destroy_user_session_path, method: :delete
Sources: