Add a person to a location

master
Matt Huntington 8 years ago
parent 7793cb0f4e
commit eca1b2d273

@ -10,6 +10,11 @@ class PeopleController < ApplicationController
end
def create
if params["id"]
params["person"]["home_id"] = params["id"].to_i
else
params["person"]["home_id"] = "NULL"
end
render json: Person.create(params["person"])
end

@ -6,6 +6,9 @@ class Person
@id = opts["id"].to_i
@name = opts["name"]
@age = opts["age"].to_i
if opts["home_id"]
@home_id = opts["home_id"]
end
end
def self.all
@ -19,7 +22,7 @@ class Person
end
def self.create(opts={})
results = DB.exec("INSERT INTO people (name, age) VALUES ( '#{opts["name"]}', #{opts["age"]} );")
results = DB.exec("INSERT INTO people (name, age, home_id) VALUES ( '#{opts["name"]}', #{opts["age"]}, #{opts["home_id"]} );")
return { created:true }
end

@ -17,4 +17,7 @@ Rails.application.routes.draw do
post '/companies', to: 'companies#create'
delete '/companies/:id', to: 'companies#delete'
put '/companies/:id', to: 'companies#update'
post '/locations/:id/people', to: 'people#create'
end

Loading…
Cancel
Save