Chapter 3 in the railstutorial.ru book