From de856cbe55dafc91ef0ddaef04a997a2aa058f8b Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Mon, 19 Mar 2018 09:04:08 -0400 Subject: [PATCH] Create a model --- app/controllers/people_controller.rb | 6 +----- app/models/person.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 app/models/person.rb diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 7bad454..3585a4c 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -1,9 +1,5 @@ class PeopleController < ApplicationController def index - render json: [ - { name: 'Joey', age:12 }, - { name: 'Sarah', age:52 }, - { name: 'Cthulhu', age: 8000 } - ] + render json: Person.all end end diff --git a/app/models/person.rb b/app/models/person.rb new file mode 100644 index 0000000..38bc5e2 --- /dev/null +++ b/app/models/person.rb @@ -0,0 +1,9 @@ +class Person + def self.all # a static function that's called on the class itself, not an instance + [ ## ruby functions return the last line of code, so no need for an explicit 'return' statement + { name: 'Joey', age:12 }, + { name: 'Sarah', age:52 }, + { name: 'Cthulhu', age: 8000 } + ] + end +end