In the conditions of “web two zero”, the issue of ratings, plus signs, stars, karma and other self-affirmation systems is very relevant. If you approach this topic correctly, then ratings are a very cool, necessary thing. Now, many people understand that rating is not only a banal twisting of the plus / minus, but also the user's activity that is hidden to the eyes, the author's credibility and all that. A good
article on this topic was written by
alfa .
But I would like to discuss only the standard tools that the rails community has. Speech about plugins. Googling 10 minutes, I found only two. None of them did not suit me =).
In any case, here is a brief overview of these plugins (these are rather translated excerpts from reviews - I did not use these plugins and do not plan). Please drop your experience and links to other achievements of plug-ins in the comments.
')
Acts_as_rated
Related Links:
devblog.famundo.com/articles/2007/02/04/a-new-rails-plugin-acts_as_ratedwww.rubynaut.net/articles/2007/03/18/rails_ajax_rating_system_part_1rubyforge.org/projects/acts-as-ratedThe main declared advantage of the plugin is a lot of customizable options and caching, which reduces the number of calls to the database.
Installation
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 immediately with a bundle of migrations, which simplifies its addition to any project. Also included tests.
Main functions
* Embedding in any model
* Rating data can be stored both in the external table and directly in the model database.
* Limit assessment limits
* Counting average and total votes and votes
* Search objects by rating or rating boundaries, as well as by rating
Acts_as_rateable
Related Links:
satishchauhan.wordpress.com/2007/08/24/star-rating-in-ruby-on-railswww.naffis.com/2006/8/31/rails-ajax-star-rating-systemrubyforge.org/projects/rateablepluginInstallation
script / plugin install svn: //rubyforge.org/var/svn/rateableplugin/trunk
migration
script / generate migration add_ratings
def self.up
create_table :ratings do |t|
t.column :rating, :integer # You can add a default value here if you wish
t.column :rateable_id :integer, :null => false
t.column :rateable_type, :string, :null => false
end
end
def self.down
drop_table :ratings
end
Usage example
class SillyWalk < ActiveRecord::Base
# attributes: name, inventor
acts_as_rateable
end
SillyWalk.new(:name => "Not Very Silly", :inventor => "Mr. Pudey").save
SillyWalk.new(:name => "A Bit Silly", :inventor => "Mrs. Two-Lumps", :rating => 3).save
SillyWalk.new(:name => "Quite Silly", :inventor => "Mr. Teabag", :rating => 5).save
# To update the rating after creation of the initial record...
SillyWalk.find_by_name("Not Very Silly").rate(1)
# You could also do this
SillyWalk.find_by_name("Not Very Silly").rating = 1
# Retreive the rating
SillyWalk.find_by_name("Not Very Silly").rating # => 1
# Find silly walks with a rating of at least 3
SillyWalk.find_all_by_rating(3..-1) # => ["A Bit Silly", "Quite Silly"]
# Find silly walks with a rating of 5 (only)
SillyWalk.find_all_by_rating(5) # => ["Quite Silly"]
# Find silly walks with a rating of 1 or 5
SillyWalk.find_all_by_rating([1,5]) # => ["Not Very Silly", "Quite Silly"]
# Find silly walks with a rating between 3 and 5, inclusive
SillyWalk.find_all_by_rating(3..5) # => ["A Bit Silly", "Quite Silly"]
# You can also mix specific ratings and ranges...
SillyWalk.find_all_by_rating([1,3..5]) # => ["Not Very Silly", "A Bit Silly", "Quite Silly"]
Main functions
* Built into any model.
methods* rate (int) - value object
* rating = - the same
* rating - returns object rating
* find_all_by_rating - returns all objects that meet the condition
* find_by_rating - returns the first object that fulfills the condition
Conclusion
These two representatives are very limited and only cope with the task of giving a person the opportunity to say good / bad. This is of course something, but obviously not enough. Therefore, the conclusion - to write something of their own.