Forum: Ruby on Rails newbie: tags (or habtm) howto?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
224047d4b6affc55a991d58833d58956?d=identicon&s=25 bjung (Guest)
on 2007-02-18 08:44
(Received via mailing list)
I there some place that has a good walk through on implementing

Basically, I have a table of things a table of tags. the things have a
many-to-many relationship to tags. I can get tags for a thing by
thing.tags but i'm at a loss as to how to get things back that are
tagged with multiple tags --

ie. if i were writing sql:

SELECT thing_id
FROM thing
    JOIN thing_tag AS thing_tag_1 ON (thing.thing_id =
    JOIN tag AS tag_1 ON (thing_tag_1.tag_id = tag_1.tag_id)
    JOIN thing_tag AS thing_tag_2 ON (thing.thing_id =
    JOIN tag AS tag_2 ON (thing_tag_2.tag_id = tag_2.tag_id)
WHERE tag_1.tag = 'foo'
    AND tag_2.tag = 'bar'

help!! thanks!
72f8ab180f81f9c544e2b58da399c0be?d=identicon&s=25 Elad Meidar (eizesus)
on 2007-02-18 15:59

Just use acts_as_taggable, it's easy and works great.

224047d4b6affc55a991d58833d58956?d=identicon&s=25 bjung (Guest)
on 2007-02-18 18:39
(Received via mailing list)
Thanks, Elad. It seems like there's some question as to whether to use
the gem or the plug-in. Any thoughts?

FYI, for anyone else dickering around with this sort of thing, I found
this helpful:

Intersection (AND)
Query for "bookmark+webservice+semweb":
FROM scBookmarks b, scCategories c
WHERE c.bId = b.bId
AND (c.category IN ('bookmark', 'webservice', 'semweb'))

the having count() thing is cute.
B2896675ee61d866e6a5a19407730602?d=identicon&s=25 (Guest)
on 2007-02-18 19:15
(Received via mailing list)
I currently use the acts_as_taggable plugin because I need to tag
stuff on multiple tables and if you use the gem version you need a
taggings tables for each one of those tables. So if you need to tag a
lot of different I'd go with the plugin, or else the gem which has
some goodies built-in like tags cloud.

Unfortunately, both seem to be have no more development at all :(
This topic is locked and can not be replied to.