Ruby On Rails Lesson
We start with the edit form, whose mockup appears in Figure 9.1.1 As usual, we’ll begin with some tests. First, note the link to change the Gravatar image; if you poke around the Gravatar site, you’ll see that the page to add or edit images is located at http://gravatar.com/emails, so we test the edit page for a link with that URI.2
The tests for the edit user form are analogous to the test for the new user form in Listing 7.31 from the Chapter 7 exercises, which added a test for the error message on invalid submission. The result appears in Listing 9.1.
To write the application code, we need to fill in the edit action in the Users controller. Notefrom Table 7.1 that the proper URI for a user’sedit pageis /users/1/edit (assuming the user’s id is 1). Recall that theid of the user is availablein the params[:id] variable, which means that we can find the user with the code in Listing 9.2.