From c20ce738afd48a26c2fe0f2a9ddd30b848767bb6 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Thu, 15 Mar 2018 10:34:14 -0400 Subject: [PATCH] using fruit class --- app/controllers/fruits_controller.rb | 6 +----- app/models/fruit.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 app/models/fruit.rb diff --git a/app/controllers/fruits_controller.rb b/app/controllers/fruits_controller.rb index b6f46a0..b538777 100644 --- a/app/controllers/fruits_controller.rb +++ b/app/controllers/fruits_controller.rb @@ -2,10 +2,6 @@ class FruitsController < ApplicationController def index # render({ :json => { :message => 'hi', :status => 200 } }) # render json: message: 'hi', status: 200 # doesn't work because nested objects are unguessable - render json: [ - { name: 'apple', color: 'red', readyToEat: true }, - { name: 'banana', color: 'yellow', readyToEat: false }, - { name: 'pineapple', color: 'yelow', readyToEat: true } - ] + render json: Fruit.all end end diff --git a/app/models/fruit.rb b/app/models/fruit.rb new file mode 100644 index 0000000..e56dd51 --- /dev/null +++ b/app/models/fruit.rb @@ -0,0 +1,9 @@ +class Fruit + def self.all + [ + { name: 'apple', color: 'red', readyToEat: true }, + { name: 'banana', color: 'yellow', readyToEat: false }, + { name: 'orange', color: 'orange', readyToEat: false } + ] + end +end