blob: 0985e7c326a7f50d3ee2310ad7154f3c348c84c4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# frozen_string_literal: true
# ProductReview
# review: text
# rating: integer
class ProductReview < ApplicationRecord
belongs_to :user_account
belongs_to :product
validates :review, presence: true
validates :rating, presence: true, inclusion: { in: 1..5 }
validate :sole_user_review
def sole_user_review
return if ProductReview.find_by(user_account_id:, product_id:).nil?
errors.add(:review, 'User has already published a review')
end
end
|