Adding tags to posts in Ruby on Rails

user142019 picture user142019 · Jan 12, 2010 · Viewed 9k times · Source

I am creating a blog in Rails using Scaffolding. I want to add a 'tags' field on each post like on StackOverflow and WordPress. I can do this with the string type ( rails generate scaffold post title:string body:text tags:string ) and then comma separated, but it's not good practice since I want the reader to browse by tags ( e.g. /tags/web20 or /tags/lol ). How can I do this?

Answer

molf picture molf · Jan 12, 2010

Tagging is so common that implementations are a commodity. I believe "acts as taggable on" is usually the preferred way of implementing tags.

See other popular solutions here.

If you wish to implement it yourself, you could dive into the source code to find some ideas.