Class: Admin::ReferenceTypesController
- Inherits:
-
AdminController
- Object
- ApplicationController
- AdminController
- Admin::ReferenceTypesController
- 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
-
#create ⇒ Object
POST /admin/reference_types or /admin/reference_types.json.
-
#destroy ⇒ Object
DELETE /admin/reference_types/1 or /admin/reference_types/1.json.
-
#edit ⇒ Object
GET /admin/reference_types/1/edit.
-
#index ⇒ Object
GET /admin/reference_types or /admin/reference_types.json.
-
#new ⇒ Object
GET /admin/reference_types/new.
-
#show ⇒ Object
GET /admin/reference_types/1 or /admin/reference_types/1.json.
-
#sort ⇒ Object
POST /admin/reference_types/sort.
-
#update ⇒ Object
PATCH/PUT /admin/reference_types/1 or /admin/reference_types/1.json.
Instance Method Details
#create ⇒ Object
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 |
#destroy ⇒ Object
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 |
#edit ⇒ Object
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 |
#index ⇒ Object
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 |
#new ⇒ Object
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 |
#show ⇒ Object
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 |
#sort ⇒ Object
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 |
#update ⇒ Object
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 |