Created
August 5, 2020 17:40
-
-
Save sandeshbodake/84559615794b5cc772540a98dbd4088c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def self.export_data_to_csv | |
| headers = ["Zipcode", "Locality Type", "Locality Name", "State", "State Abbr", "Country"] | |
| Locality.all.grou_by(&:state_abbr).each do |state, records| | |
| file = File.new("public/#{state}.csv", "w") | |
| CSV.open(file, 'w', write_headers: true, headers: headers) do |writer| | |
| records.each do |locality| | |
| writer << [locality.zipcode, locality.locality_type, locality.name, locality.state, locality.state_abbr, locality.country] | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment