2.2 - Lister les creatures

pull/1/head
Karim Bogtob 2 years ago
parent 7c3e5d79bb
commit ee35dacff7

@ -1,6 +1,11 @@
class CreaturesController < ApplicationController class CreaturesController < ApplicationController
SHOWABLE_ATTRIBUTES = [:id, :name, :health_points] SHOWABLE_ATTRIBUTES = [:id, :name, :health_points]
def index
@creatures = Creature.all
render json: @creatures.as_json(only: SHOWABLE_ATTRIBUTES)
end
def show def show
@creature = Creature.find(params[:id]) @creature = Creature.find(params[:id])
render json: @creature.as_json(only: SHOWABLE_ATTRIBUTES) render json: @creature.as_json(only: SHOWABLE_ATTRIBUTES)

@ -3,6 +3,7 @@ Rails.application.routes.draw do
get '/dice-rolls/:dice_type/(:rolls_count)', to: "dice_rolls#rolls" get '/dice-rolls/:dice_type/(:rolls_count)', to: "dice_rolls#rolls"
# CRUD Créatures # CRUD Créatures
get '/creatures', to: 'creatures#index'
get '/creatures/:id', to: 'creatures#show' get '/creatures/:id', to: 'creatures#show'
# Defines the root path route ("/") # Defines the root path route ("/")

Loading…
Cancel
Save