Check if user has voted before sign in

This commit is contained in:
María Checa
2017-10-06 01:18:56 +02:00
parent 0cf5299846
commit c3f778bbdd
2 changed files with 5 additions and 1 deletions

View File

@@ -41,4 +41,8 @@ module PollsHelper
booth.name + location booth.name + location
end end
def voted_before_sign_in(question)
current_user.current_sign_in_at >= question.poll.voters.find_by_user_id(current_user).updated_at
end
end end

View File

@@ -1,7 +1,7 @@
<div class="poll-question-answers"> <div class="poll-question-answers">
<% if can? :answer, question %> <% if can? :answer, question %>
<% question.question_answers.each do |answer| %> <% question.question_answers.each do |answer| %>
<% if @answers_by_question_id[question.id] == answer.title %> <% if @answers_by_question_id[question.id] == answer.title && !voted_before_sign_in(question) %>
<span class="button answered" <span class="button answered"
title="<%= t("poll_questions.show.voted", answer: answer.title)%>"> title="<%= t("poll_questions.show.voted", answer: answer.title)%>">
<%= answer.title %> <%= answer.title %>