class CharactersController < ApplicationController skip_before_action :redirect_if_no_active_character, only: [:new, :create] def show @character = Character.find(params[:id]) end def new @character = Character.new end def create @character = Character.new(character_params) @character.user = current_user if @character.save current_user.update(active_character: @character) redirect_to @character else flash[:alert] = "Error creating character: #{@character.errors.full_messages.join(", ")}" redirect_to action: :new end end def set_combat_styles @character = Character.find(params[:character_id]) unless @character == current_char flash[:alert] = "You can't set the combat styles of another character." redirect_to character_path(@character) and return end if @character.update(offensive_style: params[:offensive_style], defensive_style: params[:defensive_style]) flash[:notice] = "Changed combat styles to #{@character.offensive_style} and #{@character.defensive_style}." else flash[:alert] = "Failed to set combat styles." end redirect_to character_path(@character) end private def character_params params.require(:character).permit(:name) end end