Sha256: de931988d29ba16741aa6e90fc867d2cfcaf527b90cc09a417bce186e63b97ea

Contents?: true

Size: 1.78 KB

Versions: 4

Compression:

Stored size: 1.78 KB

Contents

= Voteable Mongoid

Voteable Mongoid allows you to make your Mongoid::Document objects voteable (up or down)

For instance, in a Q&A site, a user can vote up (or down) on a post or a comment.

When user provided enough information, voteable_mongoid will use only one update-in-place operation per collection.

== Installation

=== Rails 3.0.x

To install the gem, add this to your Gemfile

  gem 'voteable_mongoid'

After that, remember to run "bundle install"

== Usage

=== Making Post and Comment voteable, User being the voter

post.rb

    class Post
      include Mongoid::Document
      include Mongoid::Voteable

      # set points for each vote
      vote_point self, :up => +1, :down => -1

      references_many :comments
    end

comment.rb

    require 'post'

    class Comment
      include Mongoid::Document
      include Mongoid::Voteable

      referenced_in :post

      vote_point self, :up => +1, :down => -3

      # each vote on a comment can affect votes count and point of the related post as well
      vote_point Post, :up => +2, :down => -1
    end

user.rb

    class User
      include Mongoid::Document
      include Mongoid::Voter
    end

=== Making a vote

    @user.vote(@post, :up)
    # is equivalent to
    @post.vote(:voter_id => @user.id, :value => :up)

    # this will affect @post.votes_count and @post.votes_point as well
    @user.vote(@comment, :down)

=== Getting votes count and points

    puts @post.votes_point
    puts @post.votes_count
    puts @post.up_votes_count
    puts @post.down_votes_count

=== Getting the list of voted objects (votees) of a class

    @user.votees(Post)

=== Undo a vote

    @user.unvote(@comment)

== Credits

* Alex N. - Author
* Stefan N. - Unvoting

Copyright (c) 2010-2011 Vinova Pte Ltd (http://vinova.sg)

Licensed under the MIT license.

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
voteable_mongoid-0.4.5 README.rdoc
voteable_mongoid-0.4.4 README.rdoc
voteable_mongoid-0.4.3 README.rdoc
voteable_mongoid-0.4.2 README.rdoc