populating a dropdownlist with xml data in ruby on rails

shure

New Member
I need to populate a dropdownlist in ruby on rails with the data in an xml document. The xml document is formatted like so:\[code\]<Countries> <Country> <CountryCode>US</CountryCode> <CountryName>United States</CountryName> </Country> ...</Countries>\[/code\]I then tried to convert to a hash using this code:\[code\]<% countries_xml = File.read(".../countries.xml") %><% countries = Hash.from_xml(countries_xml) %>\[/code\]And I got a hash like this:\[code\]{"Countries"=>{"Country"=>[{"CountryCode"=>"US", "CountryName"=>"United States"}, ... ]}}\[/code\]And I'm trying to use this hash to populate the dropdownlist but I think I am stuck. I've tried like this:\[code\]<% user.select :country, countries["Countries"]["Country"].each %>\[/code\]But this just fills the dropdownlist with hashes because the countries object is a hash of an array of hashes or something like that. I need it so that the CountryNames are in the dropdownlist and the CountryCodes are sent when the user posts the form.
 
Back
Top