Links
acts_as_voteable
Categories
acts_as_voteable
Adds acts_as_voteable functionality to ActiveRecord models, which allows you to associate a vote for or against a model instance.
Vitals
| Home | http://www.juixe.com/techknow/index.php/2006/06/24/acts-as-voteable-rails-plugin/ |
|---|---|
| Repository | http://juixe.com/svn/acts_as_voteable/ |
| License | Rails' (MIT) |
| Tags |
acts_as_voteable dfgfdg digg erter etyretre ls rateable retre tytr vote voting
|
| Rating | (56 votes) |
| Owner | Juixe |
| Created | 24 June 2006 |
Comments
-
the logic to check if a user has voted uses a loop, its better to just let the db to it...
def vote_for?(user) vote = Vote.find_by_user_id_and_voteable_type_and_voteable_id(user.id, self.class.name, self.id) return false = vote == nil return true end -
I found this after writing an almost identical plugin myself. One difference is that I used validates_uniqueness_of :voter_id, :scope => [:voteable_type, :voteable_id] in my Vote model to make sure that a particular user can't vote more than once, which I think is a good way to do it. Stop them at the model in case you accidentally leave a hole in your controller.

