updating: Add a person to a location

master
Matt Huntington 8 years ago
parent bee42d5fc2
commit c912091a7f

@ -12,8 +12,6 @@ class PeopleController < ApplicationController
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

@ -7,7 +7,7 @@ class Person
@name = opts["name"]
@age = opts["age"].to_i
if opts["home_id"]
@home_id = opts["home_id"]
@home_id = opts["home_id"].to_i
end
end
@ -24,9 +24,9 @@ class Person
def self.create(opts={})
results = DB.exec(
<<-SQL
INSERT INTO people (name, age)
VALUES ( '#{opts["name"]}', #{opts["age"]} )
RETURNING id, name, age;
INSERT INTO people (name, age, home_id)
VALUES ( '#{opts["name"]}', #{opts["age"]}, #{opts["home_id"] ? opts["home_id"] : "NULL"})
RETURNING id, name, age, home_id;
SQL
)
return Person.new(results.first)

Loading…
Cancel
Save