edgarjs / ajaxful-rating

Provides a simple way to add rating functionality to your application.
http://rdoc.info/projects/edgarjs/ajaxful-rating
417 stars 127 forks source link

users cannot be rateable #9

Closed soumya closed 14 years ago

soumya commented 14 years ago

While working on a project, I wanted it to work so that a user can rate another user. But I wasnt able to do it. The rateable_id and rateable_type dont get saved to the database for some reason. Is it possible to have the user model as both the rater and rateable? Please let me know if I've missed something.

edgarjs commented 14 years ago

In theory it is possible, as the methods only calls some associations, you end up with a recursive association, which works as normal. I will try this and see if there's any issue that avoids to save the polymorphic columns.

edgarjs commented 14 years ago

Please try the new version 2.2.0 and let me know if you still have problems.

mauroc commented 12 years ago

I am attempting to do the same thing as soumya. In the user model have

class User < ActiveRecord::Base ajaxful_rateable :stars => 5 ajaxful_rater end

however, when I call the

<%= ratings_for @user %>

in the .erb file (where @user is the rateable instance with id 406 and @user != current_user), it generates the following sql query:

SELECT SUM(rates.stars) AS sum_id FROM rates WHERE rates.rater_id = 406 AND rates.rater_type = 'User'

Obviously, this query returns the sum of ratings where @user is the rater, not the rateable user. What am I doing wrong?

edgarjs commented 12 years ago

It should work out of the box. You can see what's different in your application and the demo app: https://github.com/edgarjs/ajaxful-rating_demo_app/blob/master/app/models/user.rb

mauroc commented 12 years ago

ooops..turns out it was my fault. I had the wrong statement in the user model! thanks edgarjs.