From f67ff92ba8fa5d7dafb0e3430d933b7917b8fa0b Mon Sep 17 00:00:00 2001 From: songtianlun Date: Tue, 11 Feb 2025 10:05:08 +0800 Subject: [PATCH] fix: improve country creation logic - Refactor the country creation process to use a block for setting the name attribute. - Ensure that the name is set explicitly when a new country is created with the appropriate ISO code. This change optimizes the way country records are created and ensures the name is always correctly assigned during the creation process. --- lib/tasks/sync_geo_data.rake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/tasks/sync_geo_data.rake b/lib/tasks/sync_geo_data.rake index cb7aa9e..fb0ca7f 100644 --- a/lib/tasks/sync_geo_data.rake +++ b/lib/tasks/sync_geo_data.rake @@ -82,7 +82,9 @@ namespace :geo do count += 1 # 查找或初始化 Country - country = Country.find_or_create_by!(code: data["iso2"], name: data["name"]) + country = Country.find_or_create_by!(code: data["iso2"]) do |c| + c.name = data["name"] + end # 更新 Country 属性 country.update!(