Batch tagging through console

To append a tag to every topic on a forum, first ensure the tag is used on at least one topic. Then run the following (replacing testing with the name of the tag)

tag = Tag.find_by(name: 'testing')

Topic.where(archetype: 'regular').find_each do |topic|
 if topic.tags.exclude?(tag)
   topic.tags << tag
 end
end

To append a tag to every topic on the forum that does not have any tags already, first ensure the tag is used on at least one topic. Then run the following (replacing testing with the name of the tag)

tag = Tag.find_by(name: 'testing')

Topic.where(archetype: 'regular').find_each do |topic|
  if topic.tags.count == 0
    topic.tags << tag
  end
end