From a10129a82ae0dbb29be6995778e0fcf2ea44ba7d Mon Sep 17 00:00:00 2001 From: Karim Bogtob Date: Sun, 26 Mar 2023 19:10:49 +0200 Subject: [PATCH] TP5 - Premieres validations --- app/models/creature.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/models/creature.rb b/app/models/creature.rb index 70eecdf..3563796 100644 --- a/app/models/creature.rb +++ b/app/models/creature.rb @@ -3,6 +3,9 @@ class Creature < ApplicationRecord enum :size, [:small, :big, :giant] + validates :name, presence: true + validates :health_points, numericality: { greater_than_or_equal_to: 0 } + def alive? self.health_points > 0 end