diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 3585a4c..5709c1d 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -2,4 +2,8 @@ class PeopleController < ApplicationController def index render json: Person.all end + + def show + render json: Person.find(params[:id]) + end end diff --git a/app/models/person.rb b/app/models/person.rb index 75ffe6f..50f450c 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -12,4 +12,9 @@ class Person results = DB.exec("SELECT * FROM people;") return results.map { |result| Person.new(result) } end + + def self.find(id) + results = DB.exec("SELECT * FROM people WHERE id=#{id};") + return Person.new(results.first) + end end diff --git a/config/routes.rb b/config/routes.rb index e1ec75e..b09e193 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,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' end