fix: handle nil country safely in geo data sync
- Update country lookup to use safe navigation operator - Ensure state creation uses safe access for country attributes These changes prevent potential errors when the country data is not available, improving the reliability of the geo data sync process.
This commit is contained in:
parent
90c9a8946b
commit
ef16242fc4
@ -130,18 +130,15 @@ namespace :geo do
|
||||
puts "Syncing State[#{count}/#{sum}] [#{data["name"]}] country:[#{data["country_name"]}]"
|
||||
count += 1
|
||||
|
||||
country =
|
||||
data["country_code"] ?
|
||||
Country.find_by!(code: data["country_code"]) :
|
||||
Country.find_by!(name: data["country_name"])
|
||||
country = Country.find_by!(code: data["country_code"])
|
||||
|
||||
state = State.find_or_create_by!(name: data["name"]) do |s|
|
||||
s.country_id = country.id
|
||||
s.country_code = country.code
|
||||
s.country_id = country&.id
|
||||
s.country_code = country&.code
|
||||
end
|
||||
|
||||
state.update!(
|
||||
country_code: country.code,
|
||||
country_code: country&.code,
|
||||
fips_code: data["fips_code"],
|
||||
iso2: data["iso2"],
|
||||
code: data["state_code"],
|
||||
|
Loading…
Reference in New Issue
Block a user