diff options
author | HombreLaser <sebastian-440@live.com> | 2023-03-22 18:01:14 -0600 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2023-03-22 18:01:14 -0600 |
commit | a92be45296f8cc3210030602bd83a8d0229206cd (patch) | |
tree | a05581fb30ec20105a074af6e6a682823429e269 /app/models/address.rb | |
parent | bf58a3a1b148ed6b1ace157cfaafe34831706721 (diff) |
Añade modelo Address
Diffstat (limited to 'app/models/address.rb')
-rw-r--r-- | app/models/address.rb | 24 |
1 files changed, 24 insertions, 0 deletions
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 |