Acts As Caesar is a voting system – allowing up/down voting of objects.
Simply add acts_as_caesar to your Gemfile
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
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
$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)
In Rails projects
//= 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.
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
Note: the RSpec test suite expects MongoDB to be running on localhost:27017 without authentication. You can customise this in
Please see LICENSE