Developed following ryanb's Railscasts episodes 196, 197