Skip to content

Instantly share code, notes, and snippets.

@catm705
Last active August 29, 2015 13:59
Show Gist options
  • Select an option

  • Save catm705/10985104 to your computer and use it in GitHub Desktop.

Select an option

Save catm705/10985104 to your computer and use it in GitHub Desktop.
API - in Seed Data
###### seed.rb ###################
######################################
Complaint.delete_all
url = "http://data.cityofnewyork.us/resource/erm2-nwe9.json"
response = HTTParty.get(url)
response.each do |incident|
# c = Complaint.new
# c.descriptor = incident["incident_descriptor"]
# c.address = incident["address"]
# c.latitude = incident["latitude"]
# c.longitude = incident["longitude"]
# c.zip = incident["incident_zip"]
# c.save
# rails c --> To check your data
# Complaint.all
Complaint.create(
descriptor: incident['descriptor'],
address: incident['incident_address'],
latitude: incident['latitude'],
longitude: incident['longitude'],
zip: incident['incident_zip']
)
end
######### index.html.erb ###################
###############################################
<h1>Complaints</h1>
<table>
<thead>
<th align="left">Descriptor</th>
<th align="left">Address</th>
<th>Longitude</th>
<th>Latitude</th>
<th>Zip</th>
</thead>
<tbody>
<% @complaints.each do |complaint| %>
<tr>
<td><%= complaint.descriptor %> </td>
<td><%= complaint.address %> </td>
<td><%= complaint['longitude'] %> </td>
<td><%= complaint['latitude'] %> </td>
<td><%= complaint['zip'] %> </td>
<% end %>
</tr>
</tbody>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment