diff --git a/app/controllers/fruits_controller.rb b/app/controllers/fruits_controller.rb index a43833f..637caa0 100644 --- a/app/controllers/fruits_controller.rb +++ b/app/controllers/fruits_controller.rb @@ -14,4 +14,8 @@ class FruitsController < ApplicationController def create render json: Fruit.create(params["fruit"]) end + + def delete + render json: Fruit.delete(params[:id]) + end end diff --git a/app/models/fruit.rb b/app/models/fruit.rb index 04f32be..30a533d 100644 --- a/app/models/fruit.rb +++ b/app/models/fruit.rb @@ -27,4 +27,9 @@ class Fruit results = DB.exec("INSERT INTO fruits (name, color, readytoeat) VALUES ( '#{opts["name"]}', '#{opts["color"]}', #{opts["readyToEat"]} );") return Fruit.new(opts) end + + def self.delete(id) + results = DB.exec("DELETE FROM fruits WHERE id=#{id};") + return { deleted: true } + end end diff --git a/config/routes.rb b/config/routes.rb index 598e466..caddaa0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,4 +4,5 @@ Rails.application.routes.draw do # get('/fruits', { :to => 'fruits#index' }) get '/fruits/:id', to: 'fruits#show' post '/fruits', to: 'fruits#create' + delete '/fruits/:id', to: 'fruits#delete' end