Class: ImprovementsController

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

Overview

Controller for Improvements

Instance Method Summary collapse

Methods inherited from ApplicationController

#check_for_mobile, #mobile_device?

Instance Method Details

#createObject

POST /improvements POST /improvements.json


31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/improvements_controller.rb', line 31

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

#destroyObject

DELETE /improvements/1 DELETE /improvements/1.json


64
65
66
67
68
69
70
# File 'app/controllers/improvements_controller.rb', line 64

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

#editObject

GET /improvements/1/edit


27
# File 'app/controllers/improvements_controller.rb', line 27

def edit; end

#indexObject

GET /improvements GET /improvements.json


9
10
11
# File 'app/controllers/improvements_controller.rb', line 9

def index
  @improvements = Improvement.all
end

#newObject

GET /improvements/new


21
22
23
24
# File 'app/controllers/improvements_controller.rb', line 21

def new
  @improvement = Improvement.new
  authorize @improvement
end

#showObject

GET /improvements/1 GET /improvements/1.json


15
16
17
18
# File 'app/controllers/improvements_controller.rb', line 15

def show
  hunter = Hunter.find_by(id: params[:hunter_id]) if params[:hunter_id]
  @improvable_options = @improvement.improvable_options(hunter) if hunter
end

#updateObject

PATCH/PUT /improvements/1 PATCH/PUT /improvements/1.json


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

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