1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-09 23:45:21 +02:00

better cleanup on address string

This commit is contained in:
Luan Estradioto 2025-04-16 14:25:22 -03:00
parent 7d79fbcceb
commit 665a478e4f
2 changed files with 6 additions and 7 deletions

View file

@ -2,14 +2,17 @@ class Address < ApplicationRecord
belongs_to :addressable, polymorphic: true
def to_s
I18n.t("address.format",
string = I18n.t("address.format",
line1: line1,
line2: line2,
county: county,
locality: locality.present? ? "#{locality}, " : "",
locality: locality,
region: region,
country: country,
postal_code: postal_code
)
# Clean up the string to maintain I18n comma formatting
string.split(",").map(&:strip).reject(&:empty?).join(", ")
end
end

View file

@ -8,8 +8,4 @@ en:
locality: Locality
postal_code: Postal Code
region: Region
format: |-
%{line1}
%{line2}
%{locality}%{region} %{postal_code}
%{country}
format: "%{line1} %{line2}, %{locality}, %{region} %{postal_code} %{country}"