blob: 6986dd425cd5d3e12a16f25880e2c980b977787b (
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, 'is invalid')
end
end
|