Create a show route

master
Matt Huntington 8 years ago
parent 6d8af5dd03
commit 424ee9b473

@ -2,4 +2,8 @@ class PeopleController < ApplicationController
def index
render json: Person.all
end
def show
render json: Person.find(params[:id])
end
end

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

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

Loading…
Cancel
Save