Description

Acts As Caesar is a voting system – allowing up/down voting of objects.

Build Status

Installation

Simply add acts_as_caesar to your Gemfile

gem "acts_as_caesar"

Requirements

You must have Redis server installed. We will seek to make the persistence layer database agnostic over time.

Candidate objects (things that are being up/downvoted, e.g. comments) must be persisted using ActiveRecord or Mongoid

You must have jQuery installed and JavaScript on the client-side is required.

Configuration

Acts As Caesar expects a Redis connection to exist on the $redis constant, if that’s not set it will connect to Redis on localhost, port 6379 (default for Redis server). You can easily create your own Redis connection using the code below (for Rails place this in config/initializers/redis.rb):

$redis = Redis.new(:host => 'localhost', :port => 6379)

Or for Heroku:

require 'uri'
uri = URI.parse(ENV["REDISTOGO_URL"])
$redis = Redis.new(host: uri.host, port: uri.port, password: uri.password)

Usage

In Rails projects

Add the JavaScript library to your app/assets/application.js file:

//= require acts_as_caesar

Mount the engine into your routes.rb file, under any path you wish:

mount ActsAsCaesar::Rails::Engine => "/acts_as_caesar"

In any ActiveModel-compatible you wish to be updated with their score include the ActAsCandidate module:

class Review < ActiveRecord::Base
  include ActsAsCaesar::ActAsCandidate
end

In your views, where you wish to display the voting buttons, call the helper as so:

<%= acts_as_caesar(candidate: review, voter: current_user, base_path: '/acts_as_caesar') %>

Note: the above base_path should match the one used in the routes file.

Testing

To run the Acts As Caesar tests, simply run rake, this will run both RSpec and Jasmine. To run just RSpec use rake spec or to run just Jasmine use rake jasmine_spec

Note: the RSpec test suite expects MongoDB to be running on localhost:27017 without authentication. You can customise this in spec/dummy/config/mongoid.yml.

License

Please see LICENSE