delete fruit route

master
Matt Huntington 8 years ago
parent ac0dc7c757
commit 8aa2521787

@ -14,4 +14,8 @@ class FruitsController < ApplicationController
def create def create
render json: Fruit.create(params["fruit"]) render json: Fruit.create(params["fruit"])
end end
def delete
render json: Fruit.delete(params[:id])
end
end end

@ -27,4 +27,9 @@ class Fruit
results = DB.exec("INSERT INTO fruits (name, color, readytoeat) VALUES ( '#{opts["name"]}', '#{opts["color"]}', #{opts["readyToEat"]} );") results = DB.exec("INSERT INTO fruits (name, color, readytoeat) VALUES ( '#{opts["name"]}', '#{opts["color"]}', #{opts["readyToEat"]} );")
return Fruit.new(opts) return Fruit.new(opts)
end end
def self.delete(id)
results = DB.exec("DELETE FROM fruits WHERE id=#{id};")
return { deleted: true }
end
end end

@ -4,4 +4,5 @@ Rails.application.routes.draw do
# get('/fruits', { :to => 'fruits#index' }) # get('/fruits', { :to => 'fruits#index' })
get '/fruits/:id', to: 'fruits#show' get '/fruits/:id', to: 'fruits#show'
post '/fruits', to: 'fruits#create' post '/fruits', to: 'fruits#create'
delete '/fruits/:id', to: 'fruits#delete'
end end

Loading…
Cancel
Save