Class: MovesController

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

Overview

Restful controller for Moves

Instance Method Summary collapse

Methods inherited from ApplicationController

#check_for_mobile, #mobile_device?

Instance Method Details

#createObject

POST /moves POST /moves.json


49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/moves_controller.rb', line 49

def create
  @move = Move.new(move_params)
  authorize @move
  respond_to do |format|
    if @move.save
      format.html { redirect_to move_path(@move), notice: 'Move was successfully created.' }
      format.json { render :show, status: :created, location: @move }
    else
      format.html { render :new }
      format.json { render json: @move.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /moves/1 DELETE /moves/1.json


79
80
81
82
83
84
85
# File 'app/controllers/moves_controller.rb', line 79

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

#editObject

GET /moves/1/edit


45
# File 'app/controllers/moves_controller.rb', line 45

def edit() end

#indexObject

GET /moves GET /moves.json


9
10
11
12
13
14
15
16
# File 'app/controllers/moves_controller.rb', line 9

def index
  @moves = params[:basic] ? Moves::Basic.all : Move.all
  with_hunter if params[:hunter_id]
  if params[:playbook_id]
    @moves = @moves.where(playbook_id: params[:playbook_id])
  end
  @moves = @moves.order(:type, :name)
end

#newObject

GET /moves/new


39
40
41
42
# File 'app/controllers/moves_controller.rb', line 39

def new
  @move = Move.new
  authorize @move
end

#rollObject

GET /moves/1/roll GET /moves/1/roll.json


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/moves_controller.rb', line 24

def roll
  hunter = Hunter.find_by(id: params[:hunter_id])
  # TODO: raise complaint id unrollable
  return unless hunter && @move.rollable?
  roll_results = if params[:lucky]
                   @luck_effect = hunter.playbook.luck_effect
                   @move.lucky_roll(hunter, params[:lose_experience])
                 else
                   @move.roll_results(hunter)
                 end
  @results = roll_results.result
  @roll = roll_results.roll
end

#showObject

GET /moves/1 GET /moves/1.json


20
# File 'app/controllers/moves_controller.rb', line 20

def show; end

#updateObject

PATCH/PUT /moves/1 PATCH/PUT /moves/1.json


65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/moves_controller.rb', line 65

def update
  respond_to do |format|
    if @move.update(move_params)
      format.html { redirect_to move_path(@move), notice: 'Move was successfully updated.' }
      format.json { render :show, status: :ok, location: @move }
    else
      format.html { render :edit }
      format.json { render json: @move.errors, status: :unprocessable_entity }
    end
  end
end