See Rails Recipes scroll down to "Part II—Database Recipes" and you can download the tagging section.