0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
A basic Mongoid voting gem which allows voting on embedded documents.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

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