votes: fix upvote ratio calculation.

Old posts don't have vote records, so we can't use vote records to
calculate the ratio.
This commit is contained in:
evazion
2021-11-21 18:06:41 -06:00
parent 00befc96f0
commit f151e93615

View File

@@ -21,7 +21,7 @@ class PostVotesTooltipComponent < ApplicationComponent
def upvote_ratio
return nil if votes.length == 0
sprintf("(%.1f%%)", 100.0 * votes.select(&:is_positive?).length / votes.length)
sprintf("(%.1f%%)", 100.0 * post.up_score / (post.up_score + post.down_score.abs))
end
def voter_name(vote)