From 58f57bc15b0ab88536e60fe987228dea3568b8d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Tue, 17 Oct 2017 13:16:46 +0200 Subject: [PATCH] Added poll method `voted_in_web?` --- app/models/poll.rb | 4 ++++ app/views/polls/show.html.erb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/poll.rb b/app/models/poll.rb index 84349bf0b..cd91db884 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -65,6 +65,10 @@ class Poll < ActiveRecord::Base Poll::Voter.where(poll: self, user: user, origin: "booth").exists? end + def voted_in_web?(user) + Poll::Voter.where(poll: self, user: user, origin: "web").exists? + end + def date_range unless starts_at.present? && ends_at.present? && starts_at <= ends_at errors.add(:starts_at, I18n.t('errors.messages.invalid_date_range')) diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index c9796b836..b81ee2c7a 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -39,7 +39,7 @@ <% else %> - <% unless current_user && @poll.votable_by?(current_user) %> + <% if current_user && @poll.voted_in_web?(current_user) %>
<%= t("polls.show.already_voted_in_web") %>