blob: 2eb906b02afa1fec83b90ddbbd9f8c61348f5c7a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
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
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
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
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
|