TP5 - Premieres validations

pull/1/head
Karim Bogtob 2 years ago
parent 3b317266c9
commit a10129a82a

@ -3,6 +3,9 @@ class Creature < ApplicationRecord
enum :size, [:small, :big, :giant] enum :size, [:small, :big, :giant]
validates :name, presence: true
validates :health_points, numericality: { greater_than_or_equal_to: 0 }
def alive? def alive?
self.health_points > 0 self.health_points > 0
end end

Loading…
Cancel
Save