Create a delete route

master
Matt Huntington 8 years ago
parent a8f81f5774
commit 5cf40e2a3c

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

@ -22,4 +22,9 @@ class Person
results = DB.exec("INSERT INTO people (name, age) VALUES ( '#{opts["name"]}', #{opts["age"]} );") results = DB.exec("INSERT INTO people (name, age) VALUES ( '#{opts["name"]}', #{opts["age"]} );")
return { created:true } return { created:true }
end end
def self.delete(id)
results = DB.exec("DELETE FROM people WHERE id=#{id};")
return { deleted: true }
end
end end

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

Loading…
Cancel
Save