The Dev Blog

Putting Family Management on Rails!

A New Version of acts_as_rated plugin

Posted by Guy Naor Sun, 18 Feb 2007 13:09:00 GMT

I just uploaded to rubyforge a new version of the acts_as_rated plugin.

This version is thanks to Tiago Serafim who tested it and proposed the needed changes needed to make it work with MySQL.

Tiago also proposed a new method: rated_by?(rater) that returns true if the object is rated by the passed rater.

Thanks Tiago!

As usual full testing is provided. There is one failure in MySQL testing due to strangeness in MySQL average handling. They do fully pass with Postgres.

Posted in , ,  | 2 comments

del.icio.us:A New Version of acts_as_rated plugin digg:A New Version of acts_as_rated plugin spurl:A New Version of acts_as_rated plugin wists:A New Version of acts_as_rated plugin simpy:A New Version of acts_as_rated plugin newsvine:A New Version of acts_as_rated plugin blinklist:A New Version of acts_as_rated plugin furl:A New Version of acts_as_rated plugin reddit:A New Version of acts_as_rated plugin fark:A New Version of acts_as_rated plugin blogmarks:A New Version of acts_as_rated plugin Y!:A New Version of acts_as_rated plugin smarking:A New Version of acts_as_rated plugin magnolia:A New Version of acts_as_rated plugin segnalo:A New Version of acts_as_rated plugin

A New Rails Plugin: acts_as_rated

Posted by Guy Naor Mon, 05 Feb 2007 03:20:00 GMT

I just released on RubyForge a new rails plugin for rating of any ActiveRecord model. The project page is at rubyforge.org/projects/acts-as-rated.

Though similar to other rating plugins, this one has a ton of options to customize, while still making it very easy to use. And most important for my use, can cache the statistics of the ratings (total/count/average) in the model itself or an external statistics table, eliminating the need to call sum/count/avg on the ratings table itself. . To install:

script/plugin install svn://rubyforge.org/var/svn/acts-as-rated/trunk/acts_as_rated

Usage example:

class Book < ActiveRecord::Base
  acts_as_rated
end

u = User.find_by_name "guy"
b = Book.find "Catch 22"
b.rate 5, u 
u = User.find_by_name "john"
b.rate 3, u

b.rating_average # => 4
Book.find_by_rating 2..3 # => [<Book:"Catch 22">]

b.find_rated_by User.find_by_name("guy") # => [<Book:"Catch 22">]

The plugin comes with a full set of migration methods to make it easy to add to any project, and it also has extensive testing included.

Features:

  • Rate any model
  • Optionally add fields to the rated objects to optimize speed
  • Optionally add an external rating statistics table with a record for each rated model
  • Can work with the added fields, external table or just using direct SQL count/avg calls
  • Use any model as the rater (defaults to User)
  • Limit the range of the ratings
  • Average, total and number of ratings
  • Find objects by ratings or rating ranges
  • Find objects by rater
  • Extensively tested

Enjoy!

Posted in , ,  | 8 comments

del.icio.us:A New Rails Plugin: acts_as_rated digg:A New Rails Plugin: acts_as_rated spurl:A New Rails Plugin: acts_as_rated wists:A New Rails Plugin: acts_as_rated simpy:A New Rails Plugin: acts_as_rated newsvine:A New Rails Plugin: acts_as_rated blinklist:A New Rails Plugin: acts_as_rated furl:A New Rails Plugin: acts_as_rated reddit:A New Rails Plugin: acts_as_rated fark:A New Rails Plugin: acts_as_rated blogmarks:A New Rails Plugin: acts_as_rated Y!:A New Rails Plugin: acts_as_rated smarking:A New Rails Plugin: acts_as_rated magnolia:A New Rails Plugin: acts_as_rated segnalo:A New Rails Plugin: acts_as_rated
Subscribe to The Dev Blog