Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ChallengeItem < ApplicationRecord
- has_many :photos
- end
- class Photo < ApplicationRecord
- belongs_to :challenge_item
- has_many :votes
- end
- class Vote < ApplicationRecord
- belongs_to :photo
- validate :vote_per_foto
- private
- def vote_per_foto
- if self.class.exists?(photo_id: photo_id, voter_string: voter_string)
- errors.add :vote, 'already voted'
- end
- end
- end
Add Comment
Please, Sign In to add comment