Class: Staff::EndpointsController

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

Overview

Staff-only CRUD functions for Endpoints

Instance Method Summary collapse

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/staff/endpoints_controller.rb', line 22

def create
  self.endpoint = Endpoint.create(endpoint_params)

  if endpoint
    logger.info "Created #{endpoint}"
    redirect_to [:staff, endpoint]
  else
    logger.warn "Unable to create '#{endpoint}' due to '#{endpoint.error_sentence}'"
    render :new
  end
end

#destroyObject



43
44
45
46
47
48
49
50
51
# File 'app/controllers/staff/endpoints_controller.rb', line 43

def destroy
  endpoint.destroy
  msg = "Deleted #{endpoint}"
  redirect_to staff_endpoints_path, notice: msg
rescue ActiveRecord::DeleteRestrictionError => e
  msg = "Unable to delete '#{endpoint}' due to '#{e}'"
  logger.error msg
  redirect_to staff_endpoint_path(endpoint), alert: msg
end

#editObject



19
20
# File 'app/controllers/staff/endpoints_controller.rb', line 19

def edit
end

#indexObject



8
9
10
# File 'app/controllers/staff/endpoints_controller.rb', line 8

def index
  self.endpoints = Endpoint.sorted
end

#newObject



12
13
14
# File 'app/controllers/staff/endpoints_controller.rb', line 12

def new
  self.endpoint = Endpoint.new
end

#showObject



16
17
# File 'app/controllers/staff/endpoints_controller.rb', line 16

def show
end

#updateObject



34
35
36
37
38
39
40
41
# File 'app/controllers/staff/endpoints_controller.rb', line 34

def update
  if endpoint.update(endpoint_params)
    redirect_to staff_endpoint_path(endpoint), notice: 'Endpoint was successfully updated'
  else
    logger.warn "Unable to update #{endpoint}: #{endpoint.error_sentence}"
    render :edit
  end
end