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
Book.find_by_rating 2..3
b.find_rated_by User.find_by_name("guy")
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 acts_as_rated, Rails, Ruby | 8 comments