2.1 - Montrer une creature

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

@ -0,0 +1,10 @@
class CreaturesController < ApplicationController
SHOWABLE_ATTRIBUTES = [:id, :name, :health_points]
def show
@creature = Creature.find(params[:id])
render json: @creature.as_json(only: SHOWABLE_ATTRIBUTES)
rescue ActiveRecord::RecordNotFound
render json: {}, status: 404
end
end

@ -2,6 +2,9 @@ Rails.application.routes.draw do
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
get '/dice-rolls/:dice_type/(:rolls_count)', to: "dice_rolls#rolls"
# CRUD Créatures
get '/creatures/:id', to: 'creatures#show'
# Defines the root path route ("/")
root 'home#welcome'
end

Loading…
Cancel
Save