From 6b1a1834ad1715145f047790c8391b8a5558bece Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Wed, 20 Dec 2023 20:34:25 +0000 Subject: Created new Operation model and fixed Event associations with it --- app/controllers/operations_controller.rb | 70 ++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 app/controllers/operations_controller.rb (limited to 'app/controllers/operations_controller.rb') diff --git a/app/controllers/operations_controller.rb b/app/controllers/operations_controller.rb new file mode 100644 index 0000000..5081932 --- /dev/null +++ b/app/controllers/operations_controller.rb @@ -0,0 +1,70 @@ +class OperationsController < ApplicationController + before_action :set_operation, only: %i[ show edit update destroy ] + + # GET /operations or /operations.json + def index + @operations = Operation.all + end + + # GET /operations/1 or /operations/1.json + def show + end + + # GET /operations/new + def new + @operation = Operation.new + end + + # GET /operations/1/edit + def edit + end + + # POST /operations or /operations.json + def create + @operation = Operation.new(operation_params) + + respond_to do |format| + if @operation.save + format.html { redirect_to operation_url(@operation), notice: "Operation was successfully created." } + format.json { render :show, status: :created, location: @operation } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @operation.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /operations/1 or /operations/1.json + def update + respond_to do |format| + if @operation.update(operation_params) + format.html { redirect_to operation_url(@operation), notice: "Operation was successfully updated." } + format.json { render :show, status: :ok, location: @operation } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @operation.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /operations/1 or /operations/1.json + def destroy + @operation.destroy! + + respond_to do |format| + format.html { redirect_to operations_url, notice: "Operation was successfully destroyed." } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_operation + @operation = Operation.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def operation_params + params.require(:operation).permit(:name) + end +end -- cgit v1.2.3