From a92be45296f8cc3210030602bd83a8d0229206cd Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Wed, 22 Mar 2023 18:01:14 -0600 Subject: AƱade modelo Address MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/address.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'app/models/address.rb') diff --git a/app/models/address.rb b/app/models/address.rb index a19addc..260407d 100644 --- a/app/models/address.rb +++ b/app/models/address.rb @@ -1,2 +1,26 @@ +# frozen_string_literal: true + +# Address +# number: string +# street: string +# zip_code: string +# country: string +# city: string class Address < ApplicationRecord + has_many :user_account_addresses + has_many :user_accounts, through: :user_account_addresses + + validates :number, presence: true + validates :number, comparison: { greater_than_or_equal_to: 0 } + validates :street, presence: true + validates :zip_code, presence: true + validates :country, presence: true + validate :valid_country + validates :city, presence: true + + def valid_country + return unless Country[country].nil? + + errors.add(:country, 'Invalid country') + end end -- cgit v1.2.3