class ApplicationController < ActionController::Base before_action :authenticate_user! before_action :redirect_if_no_active_character, unless: :devise_controller? helper_method :current_char def current_char @_current_char ||= current_user&.active_character end def redirect_if_no_active_character redirect_to new_character_path if (current_user && current_char.nil?) end private def start_activity(activity) if current_char.resting? flash[:alert] = "You can't do anything while you're resting." redirect_to character_path(current_char) and return end queued_actions = params[:actions].present? ? params[:actions].to_i - 1 : nil if current_char.start_activity(activity, queued_actions: queued_actions) redirect_to character_path(current_char) else message = "You can't do that. Check the costs and requirements. Also, you can't do anything that might result in combat if you're at max wounds." flash[:alert] = message.strip redirect_back(fallback_location: character_path(current_char)) end end end