From 3afd35371caa0677fd2f66491bd337d1673013dc Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Tue, 4 Apr 2023 17:37:23 -0600 Subject: Añadido validador de reseña única MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/product_review.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'app/models/product_review.rb') diff --git a/app/models/product_review.rb b/app/models/product_review.rb index ceade9a..0985e7c 100644 --- a/app/models/product_review.rb +++ b/app/models/product_review.rb @@ -9,4 +9,11 @@ class ProductReview < ApplicationRecord 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 -- cgit v1.2.3