How can I implement hierarchical tags (tags belonging to other tags) with acts_as_taggable_on?
Asked Answered
C

0

7

On our website for a cancer-related organization, we have a flat tag structure with tags like "Leukemia" but also "Chronic Myelogenous Leukemia" and "Acute Lymphoblastic Leukemia". We have a rule that anything tagged with a specific kind of leukemia should also be tagged with the main "leukemia" tag, but there is no programmatic link between them.

It'd be nice if there were such a link--some relation between tags describing one as being a parent/child of another--so that on, say, the "Leukemia" page we could have some links to the sub-topics: AML, CML, etc.

It look like the developers don't plan on supporting this (according to a Jan 2011 github issue), but it seems like a common enough use case that maybe someone's found a workaround, perhaps by modifying the Tag model to make tags themselves taggable (insert Xzibit photo).

Cyprinodont answered 30/1, 2012 at 18:29 Comment(6)
are you creating tags on the fly?Calesta
u can try adding a disease main category which can contain cancer types and then add tags to the problems/post.Calesta
Tags are created on the fly (via the front end admin interface by content editors). Ideally there'd be a way on the "New tag" form to select a tag's parent.Cyprinodont
You could make your Tag table 'categorizable' with awesome_nested_set or ancestry. Basically a tag could have parents and childrens. You'd might have to resort to pure sql though at some pointPrud
Ancestry is what you need as @Prud mentionedReeve
May I ask whether the record tagged with "Leukemia" should also be tagged with "Chronic Myelogenous Leukemia" or with any descendants as well?Dispread

© 2022 - 2024 — McMap. All rights reserved.