demarches-normaliennes/app/models/champs/pays_champ.rb
Pierre de La Morinerie 905fca0bd3 models: ensure Champs::Pays#to_s is always a string
Before this, the result of `Champs::Pays#to_s` could be `nil`, which
would break various things (like the PDF rendering of these champs).
2021-09-07 10:47:18 -05:00

36 lines
1,021 B
Ruby

# == Schema Information
#
# Table name: champs
#
# id :integer not null, primary key
# data :jsonb
# fetch_external_data_exceptions :string is an Array
# private :boolean default(FALSE), not null
# row :integer
# type :string
# value :string
# created_at :datetime
# updated_at :datetime
# dossier_id :integer
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer
#
class Champs::PaysChamp < Champs::TextChamp
def localized_value
if external_id
I18nData.countries(I18n.locale)[external_id].to_s
else
value.present? ? value.to_s : ''
end
end
def to_s
localized_value
end
def for_tag
localized_value
end
end