Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

simple voting gem for Ruby on Rails.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .DS_Store
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 voter_love.gemspec
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.