Project

voter_love

0.0
No commit activity in last 3 years
No release in over 3 years
The voter_love Gem allows users to easily vote on objects
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0.0
~> 2.5.0
~> 1.3.0

Runtime

~> 3.1.0
 Project Readme

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