You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
correction-tp-rails/app/controllers/creatures_controller.rb

15 lines
414 B

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)
rescue ActiveRecord::RecordNotFound
render json: {}, status: 404
end
end