Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show previous rating instead of average? #27

Open
gosuto opened this issue Apr 7, 2013 · 3 comments
Open

Show previous rating instead of average? #27

gosuto opened this issue Apr 7, 2013 · 3 comments

Comments

@gosuto
Copy link

gosuto commented Apr 7, 2013

It would nice if there was the option to show the user's previous rating instead of the average.

@hkawashima
Copy link

Would love this feature as well.

@petehuang
Copy link
Contributor

We created this solution that draws heavily upon the ratings_for feature already built in:

def rating_for_user(rateable_obj, rating_user, dimension = nil, options = {})
@object = rateable_obj
@user = rating_user
@Rating = Rate.find_by_rater_id_and_rateable_id_and_dimension(@user.id, @object.id, dimension)
stars = @Rating.stars

disable_after_rate = options[:disable_after_rate] || false

readonly=false
if disable_after_rate
readonly = current_user.present? ? !rateable_obj.can_rate?(current_user.id, dimension) : true
end

content_tag :div, '', "data-dimension" => dimension, :class => "star", "data-rating" => stars,
"data-id" => rateable_obj.id, "data-classname" => rateable_obj.class.name,
"data-disable-after-rate" => disable_after_rate,
"data-readonly" => readonly,
"data-star-count" => stars
end

Rather than calculate the average, this will search for an individual rating by the rating user and the rateable object (optionally, any rating dimension).

@gosuto
Copy link
Author

gosuto commented Jun 10, 2013

I actually forked this and re-wrote to my liking (changed the way it handled re-rating by the same user, averages, shows the previous rating for the user instead of the average, etc), but I'm thinking it is too use-case-specific to do a pull request to merge back into the master branch. Also it was my first time collaborating on a public repo, so I did it all wrong and github doesn't show the diffs so it is hard to see what I changed. When I have time I'll do it properly so people can use my fork with confidence if their use case deems it necessary. I use my fork in a production app and it works well for our needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants