@ -1,4 +1,6 @@
class PeopleController < ApplicationController
skip_before_action :verify_authenticity_token
def index
render json: Person.all
end
@ -6,4 +8,8 @@ class PeopleController < ApplicationController
def show
render json: Person.find(params[:id])
def create
render json: Person.create(params["person"])
@ -17,4 +17,9 @@ class Person
results = DB.exec("SELECT * FROM people WHERE id=#{id};")
return Person.new(results.first)
def self.create(opts={})
results = DB.exec("INSERT INTO people (name, age) VALUES ( '#{opts["name"]}', #{opts["age"]} );")
return { created:true }
@ -2,4 +2,5 @@ Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
get '/people', to: 'people#index'
get '/people/:id', to: 'people#show'
post '/people', to: 'people#create'