Question

I have a rails app that includes tagging for blog posts using the gem acts-as-taggable-on. My idea is to extend the tagging mechanism of this gem using a moderate-link approach where I can choose to create a few users as tag owners and they can choose to link one tag to another as parent/child.

Presently the system has independent tags like Education, Child Education and Distance Education

The tag owner of Education can choose to select Child Education and Distance Education as first level child and link them together. This relationship wont be visible until its approved by the Taxonomist(A tag administrator).

Similarly, an end user can also suggest Distance Education tag to be the child of Education and this request will become visible to the tag administrator. Based on his approval the relationship will be established.

These are the few questions I have pertaining to the requirement above:-

  1. Is it recommended to extended the gem or should I use an independent tagging model written from scratch to support this hierarchical system ?

  2. If I go ahead with the schema provided by the gem , what kind of a model should be used to design such a requirement. Specifically, should I use a single table with a parent_id column with the tag id and tag name ? Or should I maintain their relationship in a separate table with many-to-many associations (tag_id, parent_tag_id (as Foreign key)).

  3. I am also new to data structures so I will need some initial inputs on the choice of algorithms to efficiently traverse between a tag family. Using linked list was one my options however considering Rails mantra of convention over configuration , I am really unsure of how to proceed on this.

Was it helpful?

Solution

I remember doing something similir like 4 years ago with ActsAsTree.

There s also an example of how to do it manually here.

Both options will need that parent_id column on your tags table and are really straightforward. Just create a tag.rb in your models folder and extend Tag class.

Ps. Its been a long time, but i remember having to check that there are no loops, just keep it in mind

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top