]> git.openstreetmap.org Git - rails.git/commitdiff
Update country.rb
authorardean80 <ardean80@hotmail.com>
Fri, 16 Feb 2018 13:43:53 +0000 (14:43 +0100)
committerGitHub <noreply@github.com>
Fri, 16 Feb 2018 13:43:53 +0000 (14:43 +0100)
Without adding "Rails.root.join(...)" (or something else returning a complete path to the countries.xml file) this error occurred:
"No such file or directory @ rb_sysopen - config/countries.xml"
I think it happened because it could not find that file through a relative path.

lib/country.rb

index 3af7e0a211cb70e358c9ade41eeead922d009838..ab88072ecd048d9b86faadcc198f653ae29ffc98 100644 (file)
@@ -19,7 +19,7 @@ class Country
 
   def self.load_countries
     countries = {}
 
   def self.load_countries
     countries = {}
-    xml = REXML::Document.new(File.read("config/countries.xml"))
+    xml = REXML::Document.new(File.read(Rails.root.join("config", "countries.xml")))
 
     xml.elements.each("geonames/country") do |ele|
       code = ele.get_text("countryCode").to_s
 
     xml.elements.each("geonames/country") do |ele|
       code = ele.get_text("countryCode").to_s