A basic gem that adds voting capabilities to a Mongoid document. Will work on embedded documents.
To install the gem, add this to your Gemfile:
gem 'mongoid_vote'
Run:
bundle install
Then add this to the document model you’d like to add voting capabilites to:
include MongoidVote::Voteable
@comment.upvote(@user) # up vote @comment.downvote(@user) # down vote @comment.upvote_toggle(@user) # acts as upvote / if up vote already present, removes vote instead. (i.e. reddit style) @comment.downvote_toggle(@user) # acts as downvote / if down vote already present, removes vote instead. (i.e. reddit style) @comment.vote_count # vote count @comment.up_count # up vote count @comment.down_count # down vote count @comment.up_voters # up voters @comment.down_voters # down voters @comment.current_vote(@user) # returns :up / :down / nil
Currently only one vote is allowed per object per user (i.e. an up vote by a user will replace a previous down vote if one existed).