blob: 6d542ab0194e5a0080d5bf2ffb7e65cd424887b9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# frozen_string_literal: true
# Address
# number: integer
# street: string
# zip_code: string
# country: string
# city: string
class Address < ApplicationRecord
has_many :user_account_addresses, dependent: :destroy
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 if ISO3166::Country.codes.include?(country)
errors.add(:country, 'Invalid country')
end
end
|