blob: d851ad52208307666cacd1c62b6561d0faacbdcb (
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
|
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
private
def character_params
params.require(:character).permit(:name)
end
end
|