From f64852adf9d1ae678cf1bef62ef54f42a25d6589 Mon Sep 17 00:00:00 2001 From: David Gay Date: Thu, 27 May 2021 19:02:33 -0400 Subject: Fix bug with displaying requirements and/or cost of an activity without one --- app/controllers/activities_controller.rb | 4 ++-- app/models/activity.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb index a1a1835..c115abb 100644 --- a/app/controllers/activities_controller.rb +++ b/app/controllers/activities_controller.rb @@ -9,8 +9,8 @@ class ActivitiesController < ApplicationController redirect_to look_path else message = "You can't do that." - message += " (requires #{@activity.requirements&.join(", ")})" if @activity.requirements - message += " (costs #{@activity.costs&.join(", ")})" if @activity.costs + message += " (requires #{@activity.requirements&.join(", ")})" if @activity.requirements.any? + message += " (costs #{@activity.costs&.join(", ")})" if @activity.costs.any? flash[:alert] = message redirect_back(fallback_location: character_path(current_char)) end diff --git a/app/models/activity.rb b/app/models/activity.rb index 562abf4..c557752 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -8,7 +8,7 @@ class Activity < ApplicationRecord def costs costs = [] - self.whatnot[:cost].each do |cost| + self.whatnot[:cost]&.each do |cost| case cost[:type] when "item" costs.push "#{cost[:quantity]} #{Item.find_by_gid(cost[:gid]).name}" @@ -19,7 +19,7 @@ class Activity < ApplicationRecord def requirements requirements = [] - self.whatnot[:requirements].each do |req| + self.whatnot[:requirements]&.each do |req| case req[:type] when "skill" requirements.push "level #{req[:level]} #{Skill.find_by_gid(req[:gid]).name}" -- cgit v1.2.3