Ruby On Rails Lesson
Stats and a Follow Form
Now that our sample users have both followed user and followers arrays, we need to update the profile page and Home page to reflect this. We’ll start by making a partial to display the following and follower statistics on the profile and home pages. We’ll next add a follow/unfollow form, then make dedicated pages for showing user followed users and followers.
As noted in Section 11.1.1, the word ‘‘following’’ is ambiguous as an attribute (where user.following could reasonably mean either the followed users or the user’s followers), it makes sense as a label, as in ‘‘50 following.’’ Indeed, this is the label used by Twitter itself, a usage adopted in the mockups starting in Figure 11.1 and shown in close-up in Figure 11.10.
Thestats in Figure 11.10 consist of the number of users the current user is following and the number of followers, each of which should be a link to its respective dedicated display page. In Chapter 5, we stubbed out such links with the dummy text ’#’, but that was before we had much experience with rutes. This time, although we’ll defer the actual pages to Section 11.2.3, we’ll make the routes now, as seen in Listing 11.18. This code uses the :member method inside a resources block, which we haven’t seen before, but see if you can guess what it does. (Note: The code in Listing 11.18 should replace the resources :users.)