30 lines
710 B
Ruby
30 lines
710 B
Ruby
class Country < ApplicationRecord
|
|
extend FriendlyId
|
|
friendly_id :name, use: :slugged
|
|
|
|
belongs_to :region, optional: true
|
|
belongs_to :subregion, optional: true
|
|
has_many :cities, dependent: :restrict_with_error
|
|
has_many :states
|
|
|
|
validates :name, presence: true
|
|
validates :code, presence: true, uniqueness: true
|
|
validates :iso2, uniqueness: true, allow_blank: true
|
|
|
|
def to_s
|
|
name
|
|
end
|
|
|
|
def localized_name
|
|
I18n.t("countries.#{code}")
|
|
end
|
|
|
|
def self.ransackable_attributes(auth_object = nil)
|
|
[ "code", "created_at", "id", "id_value", "name", "region_id", "slug", "updated_at" ]
|
|
end
|
|
|
|
def self.ransackable_associations(auth_object = nil)
|
|
[ "cities", "region" ]
|
|
end
|
|
end
|