Forked from
PortalMEC / portalmec
668 commits behind the upstream repository.
-
Mateus Rambo Strey authoredMateus Rambo Strey authored
rate.rb 737 B
# == Schema Information
#
# Table name: rates
#
# id :integer not null, primary key
# approves :boolean
# user_id :integer
# review_id :integer
# created_at :datetime not null
# updated_at :datetime not null
class Rate < ApplicationRecord
# *current_user* rate a review *review*
include Trackable
belongs_to :user
belongs_to :review
validates_presence_of :user, :review
validates_inclusion_of :approves, in: [true, false]
validates_uniqueness_of :user, scope: :review
validate :cannot_rate_your_own, on: :create
def recipient
review
end
private
def cannot_rate_your_own
errors.add(:user_id, 'cannot rate your own review') if review.user == user
end
end