Class: HavensController

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

Overview

This controller handles routing for the havens endpoint

Instance Method Summary collapse

Methods inherited from ApplicationController

#check_for_mobile, #mobile_device?

Instance Method Details

#createObject

POST /havens POST /havens.json


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

def create # rubocop:disable Metrics/MethodLength
  @haven = Haven.new(haven_params)
  @haven.user = current_user
  authorize @haven
  respond_to do |format|
    if @haven.save
      format.html do
        redirect_to @haven, notice: 'Haven was successfully created.'
      end
      format.json do
        render :show, status: :created, location: @haven
      end
    else
      format.html { render :new }
      format.json do
        render json: @haven.errors, status: :unprocessable_entity
      end
    end
  end
end

#destroyObject

DELETE /havens/1 DELETE /havens/1.json


69
70
71
72
73
74
75
76
77
# File 'app/controllers/havens_controller.rb', line 69

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

#editObject

GET /havens/1/edit


24
# File 'app/controllers/havens_controller.rb', line 24

def edit; end

#indexObject

GET /havens GET /havens.json


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

def index
  @havens = Haven.all
end

#newObject

GET /havens/new


18
19
20
21
# File 'app/controllers/havens_controller.rb', line 18

def new
  @haven = Haven.new
  authorize @haven
end

#showObject

GET /havens/1 GET /havens/1.json


15
# File 'app/controllers/havens_controller.rb', line 15

def show; end

#updateObject

PATCH/PUT /havens/1 PATCH/PUT /havens/1.json


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

def update # rubocop:disable Metrics/MethodLength
  respond_to do |format|
    if @haven.update(haven_params)
      format.html do
        redirect_to @haven, notice: 'Haven was successfully updated.'
      end
      format.json { render :show, status: :ok, location: @haven }
    else
      format.html { render :edit }
      format.json do
        render json: @haven.errors, status: :unprocessable_entity
      end
    end
  end
end