Thursday, May 15, 2008

Acts_as_rated .. Rating Users

acts_as_rated is another solid plugin written by Guy Naor .

The issue I had was I wanted a user to be able to rate another user ???


From what I could tell the issue was that inorder to do this , was that the relationship now become a self referential join rather than a has_one or has_many relationship. What I did was to create a model User - has_one :user_rating and UserRating was added as acts_as_ratable. Any ways if you look within the code, there is a way of adding a statistics table, rather than changing your current model table. Which is all this is really doing and you still have the benefits of all the good stuff Guy wrote.

Also outside of the scope of rating the User model I also made significant changes to fit my use case. Overall the code is clean and easy to follow. The changes I made are for example lets say you wanted to rate actors of movies. But you wanted to allow users to rate an actor more than once based on the movie they performed on. So you would allow a user to rate Brad Pitt for the movie Seven, and Oceans 11.. etc. This was a very simple change requiring to add the ... in this case movie_id to the ratings table, and adding the condition to queries in the rate and rate_by functions.
Also it doesn't save to the decimals for example 7.5. I had to change the precision of the rating_avg columns.

1 comment:

Almost Twinkie said...

Hi,

I am trying to do the exactly the same...to rate a user using acts_as_rated. I am not very clear on how you achieved it. Is there anyway you could clarify how exactly you did it?

Thank you in advance!