Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
simple voting gem for Ruby on Rails.
Ruby
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib updated documentation, fixed bug
spec updated documentation, fixed bug
.DS_Store updated documentation, fixed bug
.gitignore updated .gitignore file
Gemfile original generated plugin
Gemfile.lock updated gemspec, lib folder files, added spec testing files, rakefile
MIT-LICENSE original generated plugin
README.rdoc
Rakefile updated documentation, fixed bug
voter_love.gemspec fixed generator bug

README.rdoc

Voter Love

A simple, easy to use Rails 3.1 voting Gem.

Installation

add the voter_love gem to your Gemfile:

gem 'voter_love'

create and generate the voter_love migration:

rails generate voter_love

you will then need to add up_votes and down_votes columns to your User (voter) and Object (e.g. links) (votable) migrations:

add_column :users, :up_votes, :integer, :null => false, :default => 0
add_column :users, :down_votes, :integer, :null => false, :default => 0
add_column :links, :up_votes, :integer, :null => false, :default => 0
add_column :links, :down_votes, :integer, :null => false, :default => 0

Usage

Turn your objects (e.g. links) into a votable model:

class Link < ActiveRecord::Base
  acts_as_votable
end

Turn your users (or any other model) into a voter model:

class User < ActiveRecord::Base
  acts_as_voter
end

To vote for an object (with an error raised if user already voted on the object):

user.up_vote(link)
user.down_vote(link)

To vote for an object (and ignore the vote if the user has already voted on the object):

user.up_vote!(link)
user.down_vote!(link)

Total score (up votes - down votes)

link.score
Something went wrong with that request. Please try again.