docbrown/app/models/poll_skip.rb
Anna Buianova f79b3cb12a Fixed rubocop issues, new .rubocop_todo.yml (#3255)
* Fixed rubocop issues, new .rubocop_todo.yml

* Refined and fixed indentation
2019-06-21 14:26:39 -04:00

12 lines
328 B
Ruby

class PollSkip < ApplicationRecord
belongs_to :poll
belongs_to :user
validate :one_vote_per_poll_per_user
private
def one_vote_per_poll_per_user
errors.add(:base, "cannot vote more than once in one poll") if poll.poll_votes.where(user_id: user_id).any? || poll.poll_skips.where(user_id: user_id).any?
end
end