From 94418789939af680ed72bf31c62762046da33dfd Mon Sep 17 00:00:00 2001 From: David Gay Date: Thu, 3 Jun 2021 19:58:16 -0400 Subject: Only allow one drink condition, too --- app/models/state.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'app/models') diff --git a/app/models/state.rb b/app/models/state.rb index 29b3f42..52767e7 100644 --- a/app/models/state.rb +++ b/app/models/state.rb @@ -21,10 +21,12 @@ class State < ApplicationRecord # Don't allow duplicate conditions; just destroy the old one. character.states.where(condition: condition).where.not(id: id).destroy_all - # Only allow one food condition. Destroy the old one. - if condition.tags.include?("food") - character.states.each do |state| - state.destroy if state.id != id && state.condition.tags.include?("food") + # Only allow one food condition and one drink condition. Destroy any old ones. + %w[food drink].each do |tag| + if condition.tags.include?(tag) + character.states.each do |state| + state.destroy if state.id != id && state.condition.tags.include?(tag) + end end end end -- cgit v1.2.3