VoteFu 0.0.7

Written by pete

Topics: Code, Rails, Ruby

A couple of contributors forked VoteFu and submitted some patches. I’ve updated the master branch to integrate the changes. Notably:

  • VoteFu now works as a standard gem in a Ruby application. (i.e. not as a Rails plugin)
  • VoteFu now works as a Rails Gem Plugin.
  • VoteFu now works with Rails 2.2.2.
  • Other assorted small bugfixes.

To install VoteFu as a Gem Plugin:

sudo gem install peteonrails-vote_fu

Then in config/environment.rb:

  config.gem "peteonrails-vote_fu", 
     :source => "http://gems.github.com", 
     :lib => "vote_fu"

And then, optionally:

rake gems:unpack

Special thanks to Jon Maddox and Bence Nagy for the updated code. Check it out yourself!

  • sherpa99

    I keep getting this error when I run the “script/generate voteable VoteableModel” command.

    “Couldn't find 'voteable' generator”

    Here's what I did,

    First I created a quick test application (rails 2.2.2)

    Then I create a quick scaffold like this:
    –> script/generate scaffold post title:string body:text published:boolean

    Then I created quick user model like this:
    –> script/generate scaffold user login:string password:string

    Then ran
    –> db:migrate

    Then ran:
    –>script/generate voteable post

    error –> Couldn't find 'voteable' generator

    I've tried using the plugin and the gem version — same results.

    Any ideas,

    Cheers,

    Rich

  • http://blog.peteonrails.com peteonrails

    Rich,

    Sorry about that! I need to update the documentation. It is now:

    “script/generate vote_fu Post”

    –Pete

  • Guillaume

    Found an issue with has_karma and sqlite3.

    module InstanceMethods
    def karma(options = {})
    # 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 with sqlite3.

    Without this fix, everyone had a karma of 0.

    Not sure this is the right place for the post, I'll try to add it on github as well.

  • http://blog.peteonrails.com peteonrails

    Thank you, Guillaume. If you'd fork the repo on github, make the change, and send me a pull request, I'll be happy to merge the changes into the master.

    If you'd rather not do it that way, then I'll make a bugfix release in the next week or so and include your changes.

  • nick

    Any idea how to mix the tally stuff with will_paginate? I've tried, but it didn't quite work out…

  • http://blog.peteonrails.com peteonrails

    I've not had a problem doing this. What problems are you encountering? What version of will_paginate are you using?

  • nick

    the latest mislav_will_paginate on github.

    If you say it should work, then what (in general) should my controller code look like?

  • nick

    Nevermind, I figured it out!
    Thanks anyway!

  • Eric

    Vote Fu and STI: I noticed that Vote Fu did not work with STI'd classes. This is because the types stored in the Vote table is always the base type, but the voteable and voter modules use self.class.name in their queries. Changing these methods to use self.class.base_class.name makes it work perfectly though. :) Great plug in. Very useful!

  • Eric

    Vote Fu and STI: I noticed that Vote Fu did not work with STI'd classes. This is because the types stored in the Vote table is always the base type, but the voteable and voter modules use self.class.name in their queries. Changing these methods to use self.class.base_class.name makes it work perfectly though. :) Great plug in. Very useful!