6

Basically I would like to add the ability to vote on tags, so I would like to have a priority column for each different model's tag.

Any ideas about how to do this?

I suspect I need to make a new migration, but I don't know what to make it for. What would the migration be?

Thanks!

bahudso
  • 159
  • 1
  • 11

2 Answers2

5

As I remember, acts_as_taggable creates a table called tags, so you add a field to that table:

rails g migration add_votes_to_tag votes:integer

and add your logic to vote on tag.

P.S. Not sure if I understood correctly your question.

rmagnum2002
  • 11,341
  • 8
  • 49
  • 86
  • That's what I was thinking, but is the other table that it creates not the one that actually links the tag to a different model? I just don't know which one really to add the column to. – bahudso Aug 08 '13 at 21:19
  • yes, there is a table that links Tag to your models, but you don't put rating for Tag in that table, that table is just to create a relation. If you want to rate your tags you need to add votes to tag table – rmagnum2002 Aug 08 '13 at 21:21
  • or describe more what you want to do, may be I got it all wrong. – rmagnum2002 Aug 08 '13 at 21:22
  • Yea it's hard to explain but I would like to have an individual vote count for each tag of a certain model. So the vote wouldnt be for the tag in general but for the tag of a specific model. Does that make sense? – bahudso Aug 08 '13 at 21:34
  • I got it, in this case you need to add votes filed to that join table, it's taggings I guess. – rmagnum2002 Aug 08 '13 at 21:37
  • I made the migration but now I need to be able to access the Taggings table, which currently I get: `uninitialized constant ActsAsTaggableOn::Taggings` Any idea about how to access items in the taggings table? – bahudso Aug 09 '13 at 13:29
  • create a model in app/models called Tagging.rb – rmagnum2002 Aug 09 '13 at 13:44
  • Well turns out it was just that extra 's' on Taggings. So just using ActsAsTaggableOn::Tagging worked perfectly. Thanks for the help! – bahudso Aug 09 '13 at 14:23
0

If you want to extend the regular usage of the tag class, seems to be the case, and create a special case for those tags that needs to be counted you can rely on a hook method from the core named [find_or_create_tags_from_list_with_context][1]

class Company < ActiveRecord::Base
    acts_as_taggable_on :markets, :locations

    def find_or_create_tags_from_list_with_context(tag_list, context)
        if context.to_sym == :markets
            MarketTag.find_or_create_all_with_like_by_name(tag_list)
        else
            super
        end
    end
end
Necronet
  • 6,704
  • 9
  • 49
  • 89