In this episode, we're focusing on how to accept friend requests in our app. Previously, we've implemented rejecting requests, but now it's time to let users connect! We start by building out a new controller—keeping with our conventions, it's called FriendPatchController
—and set up the appropriate route for handling patch requests (since we're updating an existing record).
You'll see how we use method spoofing in our form to send a patch request to the backend, and then inside the controller, we authenticate the user and handle updating the pivot table that keeps track of friend connections. The key step is setting the accepted
field to true
for the right user, signifying the request has been accepted.
We run through the process in the UI to see that the pending request disappears on both sides once accepted. Finally, we tee up the next episode, where things get a bit trickier: building a unified friends list that works regardless of who sent or received the request.