public
Description: Vote and Karma Management
Home | Edit | New

Home

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.

Last edited by sgrove, Fri Feb 13 16:31:29 -0800 2009
Home | Edit | New
Versions: