Reputation: 57
I have a country list that I have called in - and have parsed into the following format:
{"Countries"=>[{"Name"=>"ABKHAZIA", "IsoCode"=>"AB", "HasTown"=>"I"}, {"Name"=>"ANGUILLA", "IsoCode"=>"AI", "HasTown"=>"I"}, {"Name"=>"ANTIGUA", "IsoCode"=>"AG", "HasTown"=>"I"}, .... {"Name"=>"ZIMBABWE", "IsoCode"=>"ZW", "HasTown"=>"I"}]}
I want to populate a drop down list with this data. Code I am using to create the drop down box is:
def country_selection_input options = {}
options.reverse_merge!(
:attribute => :country_iso,
:collection => transaction_form.get_countries,
:input_html => {},
:prompt => 'please select',
:label => 'To Where'
)
This gives me a drop down box with a please select prompt and a list that consists of only the one word: Countries.
The data is there - but I am not sure how to get it into the drop down list - and am sure I am missing something simple. I have tried
:label_method => :Name,
but get an error message of
undefined method `Name' for #<Array:0x007fc385cecbb0>
This will probably turn into a menu as I want to take action based on the country selected - but - this is the first step - getting the list to work.
Upvotes: 0
Views: 344
Reputation: 57
The answer ended up being
def country_selection_input options = {}
countries = transaction_form.get_countries()[:Countries]
options.reverse_merge!(
:attribute => :country_iso,
:collection => countries,
:label_method => :Name,
:value_method => :IsoCode,
:input_html => {},
:prompt => 'please select',
:label => 'To Where'
)
call_input_from_args_hash options
end
Upvotes: 1