A Rails 3 Engine that provides voting functionality across multiple models.
Ruby JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
config
lib
spec
.document
.gitignore
.rspec
.rvmrc
Gemfile
Gemfile.lock
LICENSE.txt
README.mdown
Rakefile
VERSION
voting_booth.gemspec

README.mdown

VotingBooth

Installation

Add this to your Gemfile:

gem 'voting_booth'

and then run:

bundle install

Usage

Migrations

Generate a migration for the votes table with:

rails generate voting_booth:votes

Then, generate a migration for model you want to be votable, e.g.

rails generate voting_booth:votable BlogPost

and then run these migrations with

rake db:migrate

Models

For any model that can be voted on, add votable, e.g.:

# app/models/blog_post.rb
class BlogPost < ActiveRecord::Base
  votable
end

For the model that should act as the voter (typically User), add voter, e.g.:

# app/models/user.rb
class User < ActiveRecord::Base
  voter
end

Views

You can use the following helper methods in your views:

vote_for_path(@votable)
vote_against_path(@votable)

where @votable is any object that has been marked as votable.

Configuration

You can override VotingBooth's configuration by creating an initializer, e.g.

# config/initializers/voting_booth.rb
VotingBooth.positive_votes_only = true

The options that can be overrridden are specified in lib/voting_booth.rb

Credits

Copyright 2011 by Dan Hodos, sponsored by One Design Company. This code is heavily based on tally. Released under the MIT License.