VoteFu gets a couple enhancements

Written by pete

Topics: Code, Rails, Ruby

The lastest version of VoteFu has a few useful enhancements:

  1. Protect against mass assignment forgery. The params hash will only be consulted for :vote => true or false. The rest has to be assigned in the controller.
  2. The acts_as_voteable mixin now has support for tallying votes.

The documentation will be updated tonight, but briefly, here is what you can do with the new tally() method:

1
2
3
4
5
6
7
8
@items = Item.tally(
  {  :at_least => 1, 
      :at_most => 10000,  
      :start_at => 2.weeks.ago,
      :end_at => 1.day.ago,
      :limit => 10,
      :order => "items.name desc"
  })

This will select the Items with between 1 and 10,000 votes, the votes having been cast within the last two weeks (not including today), then display the 10 last items in an alphabetical list.

More to come. Enjoy!

  • TM

    The :order in the tally doesn't seem to work? Where have i done wrong?

  • http://blog.peteonrails.com peteonrails

    I'm not sure what you've done wrong. Can you post a link to a gist or other online snippet so I can see your code?

    Thanks,

    –Pete

  • http://blog.peteonrails.com peteonrails

    I'm not sure what you've done wrong. Can you post a link to a gist or other online snippet so I can see your code?

    Thanks,

    –Pete