evodata/app/controllers/checks_controller.rb
2021-12-18 16:14:50 +01:00

71 lines
1.8 KiB
Ruby

class ChecksController < ApplicationController
before_action :set_check, only: %i[ show edit update destroy ]
# GET /checks or /checks.json
def index
@checks = Check.all
end
# GET /checks/1 or /checks/1.json
def show
end
# GET /checks/new
def new
@check = Check.new
end
# GET /checks/1/edit
def edit
end
# POST /checks or /checks.json
def create
@check = Check.new(check_params)
respond_to do |format|
if @check.save
format.html { redirect_to check_url(@check), notice: "Check was successfully created." }
format.json { render :show, status: :created, location: @check }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @check.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /checks/1 or /checks/1.json
def update
respond_to do |format|
if @check.update(check_params)
format.html { redirect_to check_url(@check), notice: "Check was successfully updated." }
format.json { render :show, status: :ok, location: @check }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @check.errors, status: :unprocessable_entity }
end
end
end
# DELETE /checks/1 or /checks/1.json
def destroy
@check.destroy
respond_to do |format|
format.html { redirect_to checks_url, notice: "Check was successfully destroyed." }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_check
@check = Check.find(params[:id])
end
# Only allow a list of trusted parameters through.
def check_params
params.require(:check).permit(:name, :description, :hostname)
end
end