Skip to content

Instantly share code, notes, and snippets.

@rderoldan1
Last active December 17, 2015 10:18
Show Gist options
  • Save rderoldan1/5593505 to your computer and use it in GitHub Desktop.
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
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
<%= 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