Skip to content
Provides fields and methods for the manipulation of votes on a Mongoid model.
Find file
Latest commit 477d03d @jcoene Woopsie.. Bump.
Failed to load latest commit information.
lib Woopsie.. Bump.
spec Woopsie.. Bump.
.gitignore Initial Release
Gemfile Initial Release
README.rdoc Initial Release
Rakefile Woopsie.. Bump.
mongoid_voteable.gemspec Woopsie.. Bump.



Dead simple voting functionality for Mongoid models


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

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 1, @user     # I like this! -1, @user    # I don't like this!

Votes don't have to be up or down, they can include emphasis: 5, @user     # I LOVE this! -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
Something went wrong with that request. Please try again.