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?