Class: Admin::InspectionAreasController

Inherits:
AdminController
  • Object
show all
Defined in:
app/controllers/admin/inspection_areas_controller.rb

Overview

Controller for managing inspection areas.

Instance Method Summary collapse

Instance Method Details

#createObject

POST /inspection_areas POST /inspection_areas.json Creates a new inspection area.

Parameters:

  • inspection_area_params (Hash)

    The parameters for creating the inspection area.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/admin/inspection_areas_controller.rb', line 37

def create
  params = inspection_area_params
  params[:created_by_id] = current_user.id
  @inspection_area = InspectionArea.new(params)

  respond_to do |format|
    if @inspection_area.save
      format.html { redirect_to admin_inspection_areas_path, notice: 'Inspection area was successfully created.' }
      format.json { render :show, status: :created, location: @inspection_area }
    else
      format.html { render :new }
      format.json { render json: @inspection_area.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /inspection_areas/1 DELETE /inspection_areas/1.json Deletes an existing inspection area.



85
86
87
88
89
90
91
92
93
# File 'app/controllers/admin/inspection_areas_controller.rb', line 85

def destroy
  # deleting related inspectable items
  InspectableItem.where(inspection_area_id: @inspection_area.id).destroy_all
  @inspection_area.delete
  respond_to do |format|
    format.html { redirect_to admin_inspection_areas_path, notice: 'Inspection area was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#editObject

GET /inspection_areas/1/edit Displays a form for editing an inspection area.



30
# File 'app/controllers/admin/inspection_areas_controller.rb', line 30

def edit; end

#indexObject

GET /inspection_areas GET /inspection_areas.json Displays a list of inspection areas.



11
12
13
14
15
# File 'app/controllers/admin/inspection_areas_controller.rb', line 11

def index
  @inspection_areas = InspectionArea.order(system_id: :asc).page params[:page]

  render action: :index, layout: request.xhr?.nil?
end

#newObject

GET /inspection_areas/new Displays a form for creating a new inspection area.



24
25
26
# File 'app/controllers/admin/inspection_areas_controller.rb', line 24

def new
  @inspection_area = InspectionArea.new
end

#showObject

GET /inspection_areas/1 GET /inspection_areas/1.json Displays the details of a specific inspection area.



20
# File 'app/controllers/admin/inspection_areas_controller.rb', line 20

def show; end

#toggle_statusObject

POST /inspection_areas/toggle_status/1 Toggles the status (active/inactive) of an inspection area.



74
75
76
77
78
79
80
# File 'app/controllers/admin/inspection_areas_controller.rb', line 74

def toggle_status
  if @inspection_area.status == 'active'
    @inspection_area.update(status: 'inactive')
  else
    @inspection_area.update(status: 'active')
  end
end

#updateObject

PATCH/PUT /inspection_areas/1 PATCH/PUT /inspection_areas/1.json Updates an existing inspection area.

Parameters:

  • inspection_area_params (Hash)

    The parameters for updating the inspection area.



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/admin/inspection_areas_controller.rb', line 58

def update
  params = inspection_area_params
  params[:updated_by_id] = current_user.id
  respond_to do |format|
    if @inspection_area.update(params)
      format.html { redirect_to admin_inspection_areas_path, notice: 'Inspection area was successfully updated.' }
      format.json { render :show, status: :ok, location: @inspection_area }
    else
      format.html { render :edit }
      format.json { render json: @inspection_area.errors, status: :unprocessable_entity }
    end
  end
end