evodata/app/controllers/checks_controller.rb

63 lines
1.3 KiB
Ruby
Raw Normal View History

class ChecksController < AuthenticatedController
2023-02-26 15:09:08 +01:00
before_action :set_check, only: %i[show edit update destroy]
2021-12-18 16:14:50 +01:00
# GET /checks or /checks.json
def index
2022-01-27 15:36:40 +01:00
# @search = Check.ransack(params[:q])
# @checks = @search.result
2022-01-27 23:51:36 +01:00
@checks = Check.order(date: :desc, hostname: :asc, name: :asc).page params[:page]
2021-12-18 16:14:50 +01:00
end
2022-01-24 23:49:21 +01:00
# GET /checks/1
2021-12-18 16:14:50 +01:00
def show
end
# GET /checks/new
def new
@check = Check.new
end
# GET /checks/1/edit
def edit
end
2022-01-24 23:49:21 +01:00
# POST /checks
2021-12-18 16:14:50 +01:00
def create
@check = Check.new(check_params)
2023-02-26 15:09:08 +01:00
if @check.save
redirect_to check_url(@check), notice: "Check was successfully created."
else
render :new, status: :unprocessable_entity
end
2021-12-18 16:14:50 +01:00
end
2022-01-24 23:49:21 +01:00
# PATCH/PUT /checks/1
2021-12-18 16:14:50 +01:00
def update
2023-02-26 15:09:08 +01:00
if @check.update(check_params)
redirect_to check_url(@check), notice: "Check was successfully updated."
else
render :edit, status: :unprocessable_entity
end
2021-12-18 16:14:50 +01:00
end
2022-01-24 23:49:21 +01:00
# DELETE /checks/1
2021-12-18 16:14:50 +01:00
def destroy
@check.destroy
2022-01-24 23:49:21 +01:00
redirect_to checks_url, notice: "Check was successfully destroyed."
2021-12-18 16:14:50 +01:00
end
private
2023-02-26 15:09:08 +01:00
# 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
2021-12-18 16:14:50 +01:00
end