adapted from Railscast in Rails 3 at http://railscasts.com/episodes/405-angularjs?view=asciicast