2

I'm trying to add tagging to my rails app - I'd rather not use a plugin/gem for this though.

My needs are pretty simple:

Users can add multiple tags to a single item, they can search for items by those tags, and they can see a page which lists all the tags they've used before.

What I'm wondering is, whats the best way to go about this? An array/hash in the model being tagged? A join table?

Any suggestions would be highly appreciated.

Elliot
  • 13,580
  • 29
  • 82
  • 118

2 Answers2

6

I would use a join table between the tags and the taggableItems. Then with a before_create you could check if the tag's are already in the system and create them if they aren't in the system. Next you could use searchlogic (i think there is a rails 3 branch on github) for easy tag/taggableItems searching. And it would be nice to give the user some feedback of the available tags with some autocompletion or a short list of most used tags but that is up to you/the design.

Daniël Zwijnenburg
  • 2,550
  • 2
  • 21
  • 28
  • I agree. Tag model with many-many relationship. Can't get much simpler than @post.tags and @tag.posts. – danneu Jan 13 '11 at 21:33
1

Maybe this helps you: Best Rails Tagging Plugin/Gem

Community
  • 1
  • 1
BvuRVKyUVlViVIc7
  • 11,641
  • 9
  • 59
  • 111