diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 54eadb947..59a604810 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,8 +1,12 @@ module ApplicationHelper - def percentage(vote, debate) + def votes_percentage(vote, debate) return "0%" if debate.total_votes == 0 - debate.send(vote).percent_of(debate.total_votes).to_s + "%" + if vote == 'likes' + debate.likes.percent_of(debate.total_votes).to_s + "%" + elsif vote == 'dislikes' + (100 - debate.likes.percent_of(debate.total_votes)).to_s + "%" + end end def home_page? 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 @@