Class: Admin::ReferenceTypesController

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

Overview

Admin::ReferenceTypesController

This controller manages the CRUD operations for ReferenceType objects within the admin namespace. It includes actions to list, show, create, update, and destroy reference types, as well as a custom sort action.

Instance Method Summary collapse

Instance Method Details

#createObject

POST /admin/reference_types or /admin/reference_types.json

Creates a new reference type. If successful, redirects to the show page of the newly created reference type. Otherwise, re-renders the new form.



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/admin/reference_types_controller.rb', line 41

def create
  @reference_type = ReferenceType.new(reference_type_params)

  respond_to do |format|
    if @reference_type.save
      format.html { redirect_to admin_reference_type_path(@reference_type), notice: "Reference type was successfully created." }
      format.json { render :show, status: :created, location: @reference_type }
    else
      format.html { render :new, status: :unprocessable_entity }
      format.json { render json: @reference_type.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /admin/reference_types/1 or /admin/reference_types/1.json

Destroys a reference type. Redirects to the index page with a notice.



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

def destroy
  @reference_type.destroy!

  respond_to do |format|
    format.html { redirect_to admin_reference_types_path, status: :see_other, notice: "Reference type was successfully destroyed." }
    format.json { head :no_content }
  end
end

#editObject

GET /admin/reference_types/1/edit

Edits an existing reference type.



34
35
# File 'app/controllers/admin/reference_types_controller.rb', line 34

def edit
end

#indexObject

GET /admin/reference_types or /admin/reference_types.json

Lists all reference types.



14
15
16
# File 'app/controllers/admin/reference_types_controller.rb', line 14

def index
  @reference_types = ReferenceType.all
end

#newObject

GET /admin/reference_types/new

Initializes a new reference type.



27
28
29
# File 'app/controllers/admin/reference_types_controller.rb', line 27

def new
  @reference_type = ReferenceType.new
end

#showObject

GET /admin/reference_types/1 or /admin/reference_types/1.json

Shows a specific reference type.



21
22
# File 'app/controllers/admin/reference_types_controller.rb', line 21

def show
end

#sortObject

POST /admin/reference_types/sort

Sorts reference types based on the provided list of IDs.



86
87
88
89
# File 'app/controllers/admin/reference_types_controller.rb', line 86

def sort
  ReferenceType.sort_elements(params[:id_list])
  render body: nil
end

#updateObject

PATCH/PUT /admin/reference_types/1 or /admin/reference_types/1.json

Updates an existing reference type. If successful, redirects to the show page of the updated reference type. Otherwise, re-renders the edit form.



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

def update
  respond_to do |format|
    if @reference_type.update(reference_type_params)
      format.html { redirect_to admin_reference_type_path(@reference_type), notice: "Reference type was successfully updated." }
      format.json { render :show, status: :ok, location: @reference_type }
    else
      format.html { render :edit, status: :unprocessable_entity }
      format.json { render json: @reference_type.errors, status: :unprocessable_entity }
    end
  end
end