Skip to content
This repository has been archived by the owner on Jun 29, 2018. It is now read-only.

incorvia/mongoid_vote

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A voting gem for mongoid

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages