Announcing VoteFu

Written by pete

Topics: Code, Rails

VoteFu is a voting mixin that allows you to extend your models to vote on one another. Largely based on Cosmin Radoi’s acts_as_voteable plugin, VoteFu adds named_scope support, a set of generators to make using the plugin easier, a :polymorphic association to the voting class (so you can have more than one model type perform votes), and some enhancements for Rails 2.1.

I have simplified the code it requires to cast a vote down from three to one. After setting up your models with the proper mixin functionality, you can cast votes like this:

1
2
3
4
5
   voter.vote_for(voteable)
   # OR
   voter.vote_against(voteable)
  # OR
   voter.vote(voteable, [true | false] )

You can also use the old acts_as_voteable sytnax (which will continue to be supported):

1
2
3
4
  vote = Vote.new(:vote => true)
  m    = Model.find(params[:id])
  m.votes    << vote
  user.votes << vote

I hope you find the plugin useful. Comments and feedback welcome. If there is enough demand, I’ll open up a lighthouse project to track issues.

Grab the code from GitHub or visit the VoteFu Page.

  • http://www.startbreakingfree.com Brian

    Hey Pete, loving this plugin. I used it to get this site up and running quite quickly: http://buyersvote.com

    So thanks for contributing it!

    One comment I wanted to share: one more feature I was able to add is the ability for people to vote on votes! This sounds weird, but it's what they do on Amazon.com where they ask you, was this review helpful? yes or no

    Anyway, I tried adding acts_as_voteable to vote.rb and at first it didn't work. But I was able to get it working by adding these two lines at the top:

    require 'acts_as_voteable'
    ActiveRecord::Base.send(:include, Juixe::Acts::Voteable)

    Anyway, thanks again!

  • http://www.startbreakingfree.com Brian

    Hey Pete, loving this plugin. I used it to get this site up and running quite quickly: http://buyersvote.com

    So thanks for contributing it!

    One comment I wanted to share: one more feature I was able to add is the ability for people to vote on votes! This sounds weird, but it's what they do on Amazon.com where they ask you, was this review helpful? yes or no

    Anyway, I tried adding acts_as_voteable to vote.rb and at first it didn't work. But I was able to get it working by adding these two lines at the top:

    require 'acts_as_voteable'

    ActiveRecord::Base.send(:include, Juixe::Acts::Voteable)

    Anyway, thanks again!