@ -18,4 +18,8 @@ class FruitsController < ApplicationController
def delete
render json: Fruit.delete(params[:id])
end
def update
render json: Fruit.update(params[:id], params[:fruit])
@ -32,4 +32,9 @@ class Fruit
results = DB.exec("DELETE FROM fruits WHERE id=#{id};")
return { deleted: true }
def self.update(id, opts={})
results = DB.exec("UPDATE fruits SET name='#{opts["name"]}', color='#{opts["color"]}', readytoeat=#{opts["readyToEat"]} WHERE id=#{id} ;")
return { updated: true }
@ -5,4 +5,5 @@ Rails.application.routes.draw do
get '/fruits/:id', to: 'fruits#show'
post '/fruits', to: 'fruits#create'
delete '/fruits/:id', to: 'fruits#delete'
put '/fruits/:id', to: 'fruits#update'