No commit activity in last 3 years
No release in over 3 years
Provides fields and methods for the manipulation of votes on a Mongoid model.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.0.4
>= 2.0.0.beta.19

Runtime

>= 3.0.0.rc
>= 2.0.0.beta.16
 Project Readme

Mongoid::Voteable¶ ↑

Dead simple voting functionality for Mongoid models

Installation¶ ↑

Add to Gemfile:

gem 'mongoid_voteable'

Getting Started¶ ↑

Include the module in models where you want it:

class Post
  include Mongoid::Document
  include Mongoid::Voteable
  ...
end

Cast Votes¶ ↑

You can vote by passing an integer and a voter model to the “vote” method:

@post = Post.first
@user = User.where(:name => 'Bill') # or more likely, current_user

@post.vote 1, @user     # I like this!
@post.vote -1, @user    # I don't like this!

Votes don’t have to be up or down, they can include emphasis:

@post.vote 5, @user     # I LOVE this!
@post.vote -10, @user   # Delete it from the Interwebs

Additional Functionality¶ ↑

You’ll often want to know if a user can vote. Simple:

@post.voted? @user      # True if they've voted

You can also get a tally of the number of votes cast:

@post.vote_count        # Just one so far!

You can get the average vote:

@post.vote_average      # votes / voters.count