blob: 85804f2b88602e5b5ac6a4f280c7b127dd6411c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# 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
paginates_per 15
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
|