Ruby On Rails Lesson
In Chapter 7, we implemented user signup by making an HTML form that issued an HTTP POST request to the create action in the Users controller. The implementation of micropost creation is similar; the main difference is that, rather than using a separate page at /microposts/new, we will (following Twitter’s convention) put the form on the Home page itself (i.e., the root path /), as mocked up in Figure 10.10.
When we last left the Home page, it appeared as in Figure 5.6—that is, it had a ‘‘Sign up now!’’ button in the middle. Since a micropost creation form only makes
sense in the context of a particular signed-in user, one goal of this section will be to serve different versions of the Home page depending on a visitor’s signin status. We’ll implement this in Listing 10.31 below, but we can still write the tests now. As with the Users resource, we’ll use an integration test: