diff options
author | HombreLaser <sebastian-440@live.com> | 2023-04-13 18:14:25 -0600 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2023-04-13 18:14:25 -0600 |
commit | 4fa1f4ac81951f9b373d2167413ac3401fd8d060 (patch) | |
tree | 08c0c275d7cd2d28a00ed84c7b2f03f44404cb40 /app/models | |
parent | ad948f0507e9ca41580592d9638eae7a244d030f (diff) |
Añade servicios y validaciones de pago
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/order.rb | 1 | ||||
-rw-r--r-- | app/models/payment.rb | 7 |
2 files changed, 8 insertions, 0 deletions
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 |