diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 54eadb947..1d56ae4d3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,10 +1,5 @@ module ApplicationHelper - def percentage(vote, debate) - return "0%" if debate.total_votes == 0 - debate.send(vote).percent_of(debate.total_votes).to_s + "%" - end - def home_page? return false if user_signed_in? # Using path because fullpath yields false negatives since it contains diff --git a/app/helpers/votes_helper.rb b/app/helpers/votes_helper.rb index dafb108c7..dc1df0396 100644 --- a/app/helpers/votes_helper.rb +++ b/app/helpers/votes_helper.rb @@ -1,5 +1,18 @@ module VotesHelper + def debate_percentage_of_likes(debate) + debate.likes.percent_of(debate.total_votes) + end + + def votes_percentage(vote, debate) + return "0%" if debate.total_votes == 0 + if vote == 'likes' + debate_percentage_of_likes(debate).to_s + "%" + elsif vote == 'dislikes' + (100 - debate_percentage_of_likes(debate)).to_s + "%" + end + end + def css_classes_for_vote(votes, votable) case votes[votable.id] when true diff --git a/app/views/debates/_votes.html.erb b/app/views/debates/_votes.html.erb index 89a03752f..970bcc8a5 100644 --- a/app/views/debates/_votes.html.erb +++ b/app/views/debates/_votes.html.erb @@ -4,7 +4,7 @@ <%= link_to vote_debate_path(debate, value: 'yes'), class: "like #{voted_classes[:in_favor]}", title: t('votes.agree'), method: "post", remote: true do %> - <%= percentage('likes', debate) %> + <%= votes_percentage('likes', debate) %> <% end %> @@ -13,7 +13,7 @@