adds method voted_by?(user) to polls

This commit is contained in:
rgarcia
2017-02-08 20:35:33 +01:00
committed by Javi Martín
parent 54fbae6339
commit b601f6c33f
2 changed files with 22 additions and 0 deletions

View File

@@ -90,6 +90,10 @@ class Poll < ActiveRecord::Base
Poll::Voter.where(poll: self, user: user, origin: "web").exists?
end
def voted_by?(user)
Poll::Voter.where(poll: self, user: user).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'))