thecodecrate / city-state

Simple ruby gem to create form lists with cities and states
MIT License
306 stars 135 forks source link

Change city_lookup to load all configured cities #68

Open duduribeiro opened 9 months ago

duduribeiro commented 9 months ago

Closes #67 There is a problem with city_lookup. It only loads the cities for the first statue you called cities on. This is because cities memoizes all the cities for the country, but city_lookup only loads the cities for the state, and doesn't get called again for the other states.

Ex:

having the following db/cities-lookup.yml:

BR:
  GO:
    "Mutunópolis": "Mutunópolis"

If I load first cities for other state, it does not include this missing city:

bin/rails c
CS.cities(:sp, :br) # loading another state first
CS.cities(:go, :br).include?("Mutunópolis")

=> false

returned false but it should be true.

If I load this state first, it works correctly

bin/rails c
CS.cities(:go, :br).include?("Mutunópolis")

=> true

This commit changes city_lookup to load all the cities for the country.

viviancan commented 5 months ago

@duduribeiro Hello 👋 Any updates on this^? We are facing a similar issue when trying to add cities using the cities-lookup file. I have successfully renamed a country and state using the country and state lookup files but have not been able to add a city. Thx!

duduribeiro commented 5 months ago

hey @viviancan 👋

I'm not a maintainer of the repo, so I can't merge.

What you can do is use this commit (like I'm doing in my app).

You can add this on your Gemfile

gem "city-state", github: "duduribeiro/city-state", branch: "fix-lookup-cities"

and check if it works on your case. It worked for me

viviancan commented 5 months ago

hey @viviancan 👋

I'm not a maintainer of the repo, so I can't merge.

What you can do is use this commit (like I'm doing in my app).

You can add this on your Gemfile

gem "city-state", github: "duduribeiro/city-state", branch: "fix-lookup-cities"

and check if it works on your case. It worked for me

@duduribeiro Thank you for the tip 😄 Hopefully there will be some feedback on this issue soon!