# Clever ways of dealing with machine tags

**URL:** <https://www.ruby-forum.com/t/clever-ways-of-dealing-with-machine-tags/180241>\
**Category:** Rails\
**Created:** [December 15, 2009, 4:32pm UTC](https://www.ruby-forum.com/t/clever-ways-of-dealing-with-machine-tags/180241 "2009-12-15T16:32:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [December 15, 2009, 4:32pm UTC](https://www.ruby-forum.com/t/clever-ways-of-dealing-with-machine-tags/180241/1 "2009-12-15T16:32:00Z")

</div>

Hey all

I’m using acts\_as\_taggable\_on\_steroids. I’m about to add some methods  
for dealing with machine tags, and wondered if there was already some  
received wisdom (or even code) for doing this sort of thing.

For example, the taggable model is called ‘question’. It can have a  
curriculum subject and a curriculum ‘strand’, and also a theme, which is  
outside the context of the curriculum. I was planning on having machine  
tags like so:

curriculum:subject=Music  
curriculum:strand=Instruments  
theme:name=Christmas

Now, a question can have a lot of themes but it can only have one  
curriculum subject and one curriculum strand at a time.

So, i could have methods like this, for example, which is not very  
clever:

def subject=(s)  
#clear current subject tags, if any  
current\_subject\_tags = self.tags.select{|tag| tag.name =~  
/^curriculum:subject=/}  
unless current\_subject\_tags.blank?  
current\_subject\_tags.each do |tag|  
self.tag\_delete(tag.name)  
end  
end  
#now apply the new tag  
self.tag\_with(“curriculum:subject=#{s}”)  
end

But, like i say, this seems kind of clumsy. Is there some existing  
wisdom for this sort of thing?

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [December 15, 2009, 6:12pm UTC](https://www.ruby-forum.com/t/clever-ways-of-dealing-with-machine-tags/180241/2 "2009-12-15T18:12:20Z")

</div>

Have you looked into acts-as-taggable-on?

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [December 15, 2009, 6:19pm UTC](https://www.ruby-forum.com/t/clever-ways-of-dealing-with-machine-tags/180241/3 "2009-12-15T18:19:39Z")

</div>

Hi Nat - yes i have. We’re already using machine tags to denote context  
in other situations, and i need to stick to the machine tag format. So  
aato’s not appropriate in this instance as it uses its own mechanism for  
denoting tag context.

thanks though  
max
