summaryrefslogtreecommitdiff
path: root/app/controllers/characters_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/characters_controller.rb')
-rw-r--r--app/controllers/characters_controller.rb15
1 files changed, 9 insertions, 6 deletions
diff --git a/app/controllers/characters_controller.rb b/app/controllers/characters_controller.rb
index 77e1a94..2eb906b 100644
--- a/app/controllers/characters_controller.rb
+++ b/app/controllers/characters_controller.rb
@@ -1,8 +1,8 @@
class CharactersController < ApplicationController
skip_before_action :redirect_if_no_active_character, only: [:new, :create]
+ before_action :set_character, only: [:show, :set_combat_styles]
def show
- @character = Character.find(params[:id])
end
def new
@@ -22,11 +22,6 @@ class CharactersController < ApplicationController
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}."
@@ -40,4 +35,12 @@ class CharactersController < ApplicationController
def character_params
params.require(:character).permit(:name)
end
+
+ def set_character
+ @character = Character.find(params[:id])
+ unless current_char == @character
+ flash[:alert] = "You can only manage your own character."
+ redirect_to character_path(@character)
+ end
+ end
end