Given Ryan Bates's great tutorial on Virtual Attributes, how would I go about destroying a Tag (not Tagging) if, once the article is destroyed, that Tag is no longer used?
I tried doing something like this:
class Article < ActiveRecord::Base
...
after_destroy :remove_orphaned_tags
private
def remove_orphaned_tags
tags.each do |tag|
tag.destroy if tag.articles.empty?
end
end
end
... but that doesn't seem to work (the tags still exist after the article is deleted, even though no other article uses them). What should I be doing to accomplish this?