From c3f778bbdde2bc5c1c115e589d69142221cde40a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 6 Oct 2017 01:18:56 +0200 Subject: [PATCH] Check if user has voted before sign in --- app/helpers/polls_helper.rb | 4 ++++ app/views/polls/questions/_answers.html.erb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 27d33ea04..a676084cb 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -41,4 +41,8 @@ module PollsHelper booth.name + location 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 diff --git a/app/views/polls/questions/_answers.html.erb b/app/views/polls/questions/_answers.html.erb index ccc9f0322..7fb4a5d71 100644 --- a/app/views/polls/questions/_answers.html.erb +++ b/app/views/polls/questions/_answers.html.erb @@ -1,7 +1,7 @@
<% if can? :answer, question %> <% 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) %> "> <%= answer.title %>