Skip to content
AlainPilon edited this page Sep 12, 2010 · 4 revisions

Welcome to the vote_fu wiki!
Karma Issues:
has_karma conflicts with sqlite3 or Postgresql.

Without this fix, everyone had a karma of 0 (on sqlite3) or worse, the whole thing buckles down on postgresql (postgres is strongly typed an will not sum boolean fields). The above fix works with both.

Fix:

module InstanceMethods def karma(options = {})
  1. count the total number of votes on all of the voteable objects that are related to this object
    #The following line is not SQLite3 compatible, because boolean are stored as ‘f’ or ‘t’, not ‘1’, or ‘0’
    #self.karma_voteable.sum(:vote, options_for_karma(options))
    self.karma_voteable.find(:all, options_for_karma(options).merge(:conditions => [‘vote = ?’, true])).length
    end

Merging the options and conditions might not be the best for scalability, but it works.


How can you enforce single vote per user per votable if you are using the plugin as a gem? Shouldnt the validate_uniqueness be a config option?

Clone this wiki locally