chapter 3 of http://ruby.railstutorial.org