From ee35dacff7a57144ae50e946f3db519171f69e8e Mon Sep 17 00:00:00 2001 From: Karim Bogtob Date: Sun, 26 Mar 2023 15:52:30 +0200 Subject: [PATCH] 2.2 - Lister les creatures --- app/controllers/creatures_controller.rb | 5 +++++ config/routes.rb | 1 + 2 files changed, 6 insertions(+) diff --git a/app/controllers/creatures_controller.rb b/app/controllers/creatures_controller.rb index f3ff865..a5303d7 100644 --- a/app/controllers/creatures_controller.rb +++ b/app/controllers/creatures_controller.rb @@ -1,6 +1,11 @@ class CreaturesController < ApplicationController SHOWABLE_ATTRIBUTES = [:id, :name, :health_points] + def index + @creatures = Creature.all + render json: @creatures.as_json(only: SHOWABLE_ATTRIBUTES) + end + def show @creature = Creature.find(params[:id]) render json: @creature.as_json(only: SHOWABLE_ATTRIBUTES) diff --git a/config/routes.rb b/config/routes.rb index 7638f10..f3bf35a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,6 +3,7 @@ Rails.application.routes.draw do get '/dice-rolls/:dice_type/(:rolls_count)', to: "dice_rolls#rolls" # CRUD Créatures + get '/creatures', to: 'creatures#index' get '/creatures/:id', to: 'creatures#show' # Defines the root path route ("/")