From 4fa1f4ac81951f9b373d2167413ac3401fd8d060 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Thu, 13 Apr 2023 18:14:25 -0600 Subject: AƱade servicios y validaciones de pago MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/order.rb | 1 + app/models/payment.rb | 7 +++++++ 2 files changed, 8 insertions(+) (limited to 'app/models') diff --git a/app/models/order.rb b/app/models/order.rb index ae5a0d5..213bde9 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -7,4 +7,5 @@ class Order < ApplicationRecord has_one :payment has_many :product_orders has_many :products, through: :product_orders + accepts_nested_attributes_for :product_orders end diff --git a/app/models/payment.rb b/app/models/payment.rb index 5d5e862..4839de8 100644 --- a/app/models/payment.rb +++ b/app/models/payment.rb @@ -5,4 +5,11 @@ class Payment < ApplicationRecord has_one :order belongs_to :card + validate :card_belongs_to_user + + def card_belongs_to_user + return unless order.user_account.cards.find_by(id: card.id).nil? + + errors.add(:card_id, "doesn't belong to user") + end end -- cgit v1.2.3