/mongoid_vote

A voting gem for mongoid

Primary LanguageRuby

Mongoid-Vote

A basic gem that adds voting capabilities to a Mongoid document. Will work on embedded documents.

Installation

Rails 3.x and above

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

Usage Examples

@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

Notes

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).