In this episode, we dive into how to cancel a friend request in our app. We start by setting up everything so that users can see their outgoing and incoming friend requests in real-time from both sides, using two browser tabs with different user accounts.
The main focus is creating a controller (the FriendDestroyController
) to handle deleting a friend request, which is pretty much the same as unfriending someone—it just removes the relevant record from the database. We walk through wiring this up on both the profile and friends index pages, making sure that pressing "cancel" properly fires a DELETE request and actually removes the pending request.
We also update the views so users can see their sent (pending) requests and received friend requests, and we clean up the UI with nice feedback when there are no requests. We talk through handling both sides of the relationship—that is, canceling as the sender and rejecting as the receiver—and ensure the backend logic works efficiently regardless of who deletes the relationship.
By the end of the episode, canceling or rejecting friend requests works smoothly for both parties, and the UI updates accordingly. Next up: we'll tackle accepting friend requests!