update route

master
Matt Huntington 8 years ago
parent 6b49bfffe2
commit ec107b9d4e

@ -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])
end
end

@ -32,4 +32,9 @@ class Fruit
results = DB.exec("DELETE FROM fruits WHERE id=#{id};")
return { deleted: true }
end
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 }
end
end

@ -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'
end

Loading…
Cancel
Save