based on http://ruby.railstutorial.org/