diff options
author | David Gay <david@davidgay.org> | 2021-05-03 18:03:19 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-05-03 18:03:19 -0400 |
commit | 9729982e242b125579a996ff59579a906984c476 (patch) | |
tree | 2750c3e64dbe73c7b41c712beaa9b2dabd5d98a3 | |
parent | e8b4bf1c123ac973cf8c7fc64d9b137b5347d334 (diff) |
Add character name validation
-rw-r--r-- | app/models/character.rb | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/app/models/character.rb b/app/models/character.rb index a158d88..ebda598 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -4,6 +4,9 @@ class Character < ApplicationRecord has_many :character_items has_many :items, through: :character_items validates :name, presence: true + validates_length_of :name, maximum: 15, message: "can't be longer than 15 characters" + validates_uniqueness_of :name, message: "is already being used" + validates_format_of :name, with: /\A[a-z]+\z/i, message: "must consist of letters only" def shift_item(gid, amount) CharacterItem.transaction do |