Permalink
Browse files

Now shit works

  • Loading branch information...
1 parent e3e213b commit 9cba486aff4eaa51b3c5a612b6b5c454c00fb033 @gabrielroacueto committed Feb 17, 2017
Oops, something went wrong.
@@ -10,11 +10,19 @@ def create
render text: params[:geojson_array] # TODO: Geojson is returning a json object in the form of a string. We want to do AJAX Post
# to send the object through the JS instead of a form.
bound_data = JSON.parse(params[:geojson_array])
- bound = Bound.new
- bound.lat = bound_data["features"][0]["geometry"]["coordinates"][0][0][0]
- bound.long = bound_data["features"][0]["geometry"]["coordinates"][0][0][1]
- bound.poly_id = '233'
- bound.save
+ polygon = Polygon.new
+ polygon.name = params[:polygon_name]
+ polygon.save
+
+ # Parse through Google Maps Polygon JSON
+ bound_data["features"][0]["geometry"]["coordinates"][0].each do |b|
+ bound = Bound.new
+ bound.lat = b[0]
+ bound.long = b[1]
+ bound.polygon_id = polygon.id
+ bound.save
+ end
+
end
def show
@@ -1,2 +1,3 @@
class Bound < ApplicationRecord
+ belongs_to :polygon
end
@@ -0,0 +1,3 @@
+class Polygon < ApplicationRecord
+ has_many :bound
+end
@@ -5,6 +5,7 @@
</div>
<h2> JSON </h2>
<%= form_tag "bounds", :id => "bounds" do -%>
+ Polygon Name: <%= text_area_tag "polygon_name" -%>
GeoJSON Output: <%= text_area_tag "geojson_array" -%>
<%= submit_tag "Submit" %>
<% end -%>
@@ -0,0 +1,8 @@
+class CreatePolygons < ActiveRecord::Migration[5.0]
+ def change
+ create_table :polygons do |t|
+ t.string :name
+ t.timestamps
+ end
+ end
+end
@@ -3,8 +3,7 @@ def change
create_table :bounds do |t|
t.string :lat
t.string :long
- t.string :poly_id
-
+ t.belongs_to :polygon, foreign_key: true
t.timestamps
end
end
View
@@ -10,14 +10,22 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20170216013233) do
+ActiveRecord::Schema.define(version: 20170217012514) do
create_table "bounds", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "lat"
t.string "long"
- t.string "poly_id"
+ t.integer "polygon_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
+ t.index ["polygon_id"], name: "index_bounds_on_polygon_id", using: :btree
end
+ create_table "polygons", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
+ t.string "name"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ add_foreign_key "bounds", "polygons"
end
@@ -3,9 +3,9 @@
one:
lat: MyString
long: MyString
- poly_id: MyString
+ polygon: one
two:
lat: MyString
long: MyString
- poly_id: MyString
+ polygon: two
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the '{}' from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one: {}
+# column: value
+#
+two: {}
+# column: value
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class PolygonTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end

0 comments on commit 9cba486

Please sign in to comment.