Implement Event Ratings

This commit is contained in:
shlok007 2016-09-22 20:06:46 -04:00 committed by Shlok Srivastava
parent 5be1ad52ee
commit 20f4853487
67 changed files with 1298 additions and 378 deletions

View file

@ -0,0 +1,20 @@
class VotableField < ActiveRecord::Base
belongs_to :conference
validates :title, :votable_type, :stars, presence: true
validates :title, uniqueness: {scope: :votable_type, message: 'already exsists for the selected votable type'}
VALID_VOTABLE_TYPES = %w(Event).freeze
# ratyrate does not allow criterias to have spaces in them
validate :no_spaces_in_title
validate :correct_votable_type
private
def no_spaces_in_title
errors.add(:title, 'should not have spaces') unless title.match(/\s/).nil?
end
def correct_votable_type
errors.add(:votable_type, "should be one of the following: #{VALID_VOTABLE_TYPES.join(', ')}") unless VALID_VOTABLE_TYPES.include? votable_type
end
end