Fix: No comma when locality is empty (small fix) (#2111)

* Fix: No comma when locality is empty

* better cleanup on address string

* fix test to one-liner

* add more testing
This commit is contained in:
Luan Estradioto
2025-04-16 22:26:45 -03:00
committed by GitHub
parent 298e150f43
commit 6a21f26d2d
3 changed files with 41 additions and 7 deletions

View File

@@ -2,7 +2,7 @@ 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,
@@ -11,5 +11,8 @@ class Address < ApplicationRecord
country: country,
postal_code: postal_code
)
# Clean up the string to maintain I18n comma formatting
string.split(",").map(&:strip).reject(&:empty?).join(", ")
end
end