Ruby On Rails Lesson
With our tests in place, we’re ready to start developing the signin form. Recall from Listing 7.17 that the signup form uses the form_for helper, taking as an argument the user instance variable @user:
The main difference between this and the signin form is that we have no Session model, hence no analogue for the @user variable. This means that, in constructing the new session form, we have to give form_for slightly more information; in particular, whereas
allows Rails to infer that the action of the form should be to POST to the URI /users, in the case of sessions we need to indicate the name of the resource and the corresponding URI:
(A second option is to use form_tag in place of form_for; this might be more even idiomatically correct Rails, but it has less in common with the signup form, and at this stage I want to emphasize the parallel structure. Making a working form with form_tag is left as an exercise [Section 8.5].)
With the proper form_for in hand, it’s easy to make a signin form to match the mockup in Figure 8.1 using the signup form (Listing 7.17) as a model, as shown in Listing 8.7.