Create an update route

master
Matt Huntington 8 years ago
parent 4a5d6811b0
commit c1db2f3a42

@ -16,4 +16,8 @@ class PeopleController < ApplicationController
def delete
render json: Person.delete(params["id"])
end
def update
render json: Person.update(params["id"], params["person"])
end
end

@ -27,4 +27,9 @@ class Person
results = DB.exec("DELETE FROM people WHERE id=#{id};")
return { deleted: true }
end
def self.update(id, opts={})
results = DB.exec("UPDATE people SET name='#{opts["name"]}', age=#{opts["age"]} WHERE id=#{id} ;")
return { updated: true }
end
end

@ -4,4 +4,5 @@ Rails.application.routes.draw do
get '/people/:id', to: 'people#show'
post '/people', to: 'people#create'
delete '/people/:id', to: 'people#delete'
put '/people/:id', to: 'people#update'
end

Loading…
Cancel
Save