Last active
December 17, 2015 10:18
-
-
Save rderoldan1/5593505 to your computer and use it in GitHub Desktop.
fetch all countries via web service in rails in order to choose in a select_tag using http://api.worldbank.org
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
module ApplicationHelper | |
def select_country | |
countries = JSON.parse(open('http://api.worldbank.org/v2/es/countries?format=json&&per_page=250').read).last | |
countries.map {|key, val|[key["name"], key["iso2Code"]] unless key["name"].blank? }.compact! | |
end | |
end |
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
<%= form_for @client do|f| %> | |
. | |
. | |
<td><%= f.label :country %></td> | |
<td><%= f.select :country, options_for_select(select_country , "CO"), {:prompt => "Choose an option"}%></td> | |
. | |
. | |
<% end%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment