Class: CharactersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/characters_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /characters POST /characters.json


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/characters_controller.rb', line 30

def create
  respond_to do |format|
    @character = Character.new(character_params)

    if @character.save
      character.avatar.attach(params[:avatar]) if params[:avatar]
    end

    if @character.valid?
      format.html { redirect_to @character, status: :created, notice: 'character was successfully created.' }
      format.json { render :show, status: :created, location: @character }
    else
      format.html { render :new }
      format.json { render json: @character.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /characters/1 DELETE /characters/1.json


68
69
70
71
72
73
74
# File 'app/controllers/characters_controller.rb', line 68

def destroy
  @character.destroy
  respond_to do |format|
    format.html { redirect_to characters_url, notice: 'character was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#editObject

GET /characters/1/edit


25
26
# File 'app/controllers/characters_controller.rb', line 25

def edit
end

#indexObject

GET /characters GET /characters.json


6
7
8
# File 'app/controllers/characters_controller.rb', line 6

def index
  @characters = Character.active
end

#newObject

GET /characters/new


16
17
18
19
20
21
22
# File 'app/controllers/characters_controller.rb', line 16

def new
  if params['character']
    @character = Character.new(character_params)
  else
    @character = Character.new
  end
end

#showObject

GET /characters/1 GET /characters/1.json


12
13
# File 'app/controllers/characters_controller.rb', line 12

def show
end

#updateObject

PATCH/PUT /characters/1 PATCH/PUT /characters/1.json


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/characters_controller.rb', line 50

def update
  respond_to do |format|
    if @character.update(character_params)
      character.avatar.attach(params[:avatar]) if params[:avatar]
    end

    if @character.valid?
      format.html { redirect_to @character, notice: 'character was successfully updated.' }
      format.json { render :show, status: :ok, location: @character }
    else
      format.html { render :edit }
      format.json { render json: @character.errors, status: :unprocessable_entity }
    end
  end
end