@ -14,4 +14,8 @@ class FruitsController < ApplicationController
def create
render json: Fruit.create(params["fruit"])
end
def delete
render json: Fruit.delete(params[:id])
@ -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)
def self.delete(id)
results = DB.exec("DELETE FROM fruits WHERE id=#{id};")
return { deleted: true }
@ -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'