Ruby On Rails Lesson
Being ableto sign up users is a major milestonefor our application. Although thesample app has yet to accomplish anything useful, we have laid an essential foundation for all future development. In Chapter 8, we will complete our authentication machinery by allowing users to sign in and out of the application. In Chapter 9, we will allow all users to update their account information. We will also allow site administrators to delete users, thereby completing the full suite of the Users resource REST actions from Table 7.1. Finally, we’ll add authorization methods to our actions to enforce a site security model.
1. Verify that the code in Listing 7.29 allows the gravatar_for helper defined in Section 7.1.4 to take an optional size parameter, allowing codelike gravatar_for user, size: 40 in the view.
2 . Write tests for the error messages implemented in Listing 7.22. A suggested start appears in Listing 7.31.
3. Using the code in Listing 7.30, replace the error message for a missing password, currently ‘‘Password digest can’t be blank’’, with the more understandable ‘‘Password can’t be blank’’. (This uses Rails’ internationalization support to produce a functional but rather hacky solution.) Note that, to avoid duplication of error messages, you should also remove the password’s presence: true validation in the User model.
4. By writing the test first or by intentionally breaking and then fixing the application code, verify that the tests in Listing 7.32 correctly specify the desired behavior after saving the user in the create action.
5. As noted before, the flash HTML in Listing 7.26 is ugly. Verify by running the test suite that the cleaner code in Listing 7.33, which uses the Rails content_tag helper, also works.