evodata/app/controllers/checks_controller.rb

62 lines
1.4 KiB
Ruby
Raw Normal View History

class ChecksController < AuthenticatedController
2021-12-18 16:14:50 +01:00
before_action :set_check, only: %i[ show edit update destroy ]
# 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)
if @check.save
2022-01-24 23:49:21 +01:00
redirect_to check_url(@check), notice: "Check was successfully created."
2021-12-18 16:14:50 +01:00
else
2022-01-24 23:49:21 +01:00
render :new, status: :unprocessable_entity
2021-12-18 16:14:50 +01:00
end
end
2022-01-24 23:49:21 +01:00
# PATCH/PUT /checks/1
2021-12-18 16:14:50 +01:00
def update
if @check.update(check_params)
2022-01-24 23:49:21 +01:00
redirect_to check_url(@check), notice: "Check was successfully updated."
2021-12-18 16:14:50 +01:00
else
2022-01-24 23:49:21 +01:00
render :edit, status: :unprocessable_entity
2021-12-18 16:14:50 +01:00
end
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
# 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