Has_many_polymorphs for user owned tags

Hi all,

I’m trying to extend the tagging functionality of has_many_polymorphs to
work with user owned tags - ie, putting belongs_to :user in the Tagging
model.

So I changed the index in the generated migration, and added user_id to
the taggings table.

Then I added belongs_to :user in the Tagging model.

In the lib/tagging_extensions.rb file I added a new function:

def _add_tags_from_user incoming, user
  taggable?(true)
  tag_cast_to_string(incoming).each do |tag_name|
    begin
      tag = Tag.find_or_create_by_name(tag_name)
      raise Tag::Error, "tag could not be saved: #{tag_name}" if

tag.new_record?
Tagging.create(:tag => tag, :taggable => self, :user_id =>
user.id)
rescue ActiveRecord::StatementInvalid => e
raise unless e.to_s =~ /duplicate/i
end
end
end

My first problem is that if a two users tag an object with the same tag,
then I get that tag returned twice - even when I’ve added :uniq => true
to the has_many_polymorphs directive in the Tag model.

My second is that I’m unsure about how to modify the
tagging_extensions.rb to remove user owned tags. Has anyone done this
before?

Any suggestions, greatly appreciated!

Cheers,

Tom