.2. Create and run the ThumbsUp migration:
.3. setting the model that act as voter
class User < ActiveRecord::Base
setting the model that can be voted
class Comment < ActiveRecord::Base
voter.vote_for(voteable) # Adds a +1 vote
voter.vote_against(voteable) # Adds a -1 vote
voter.vote(voteable, vote)
# Adds either a +1 or -1 vote: vote => true (+1), vote => false (-1)
voter.vote_exclusively_for(voteable)
# Removes any previous votes by that particular voter, and votes for.
voter.vote_exclusively_against(voteable) # Removes any previous votes by that particular voter, and votes against.
positiveVoteCount = voteable.votes_for
negativeVoteCount = voteable.votes_against
plusminus = voteable.plusminus # Votes for minus votes against.
voter.voted_for?(voteable) # True if the voter voted for this object.
voter.vote_count(:up | :down | :all) # returns the count of +1, -1, or all votes
voteable.voted_by?(voter) # True if the voter voted for this object.
voters = voteable.voters_who_voted
Note : ThumbsUp by default only allows one vote per user.
This can be changed by removing:
validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id]
add_index :votes, ["voter_id", "voter_type", "voteable_id", "voteable_type"], :unique => true, :name => "uniq_one_vote_only"