based on tutorial at http://ruby.railstutorial.org/chapters/beginning