Can you not just validate the uniqueness of the voter_id
and candidate_id
in the Vote
table?
class Vote < ActiveRecord::Base
validates_uniqueness_of :voter_id, scope: :candidate_id
end
You should add an index to the DB too:
add_index "votes", ["voter_id", "candidate_id"], unique: true