Chapter 3 from http://ruby.railstutorial.org/