Guest User

Untitled

a guest
Nov 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. class ChallengeItem < ApplicationRecord
  2. has_many :photos
  3. end
  4.  
  5. class Photo < ApplicationRecord
  6. belongs_to :challenge_item
  7. has_many :votes
  8. end
  9.  
  10. class Vote < ApplicationRecord
  11. belongs_to :photo
  12. validate :vote_per_foto
  13.  
  14. private
  15.  
  16. def vote_per_foto
  17. if self.class.exists?(photo_id: photo_id, voter_string: voter_string)
  18. errors.add :vote, 'already voted'
  19. end
  20. end
  21. end
Add Comment
Please, Sign In to add comment