84 lines
2.2 KiB
Ruby
84 lines
2.2 KiB
Ruby
class ChecksController < ApplicationController
|
|
before_action :set_check, only: %i[show edit update destroy]
|
|
|
|
# GET /checks or /checks.json
|
|
def index
|
|
@pagy, @checks = pagy(Check.search(filter_params[:s]))
|
|
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 do
|
|
redirect_to check_url(@check),
|
|
notice: t('scaffold.model_created_successfully', model: @check.model_name.human)
|
|
end
|
|
format.json { render :show, status: :created, location: @check }
|
|
else
|
|
flash[:alert] = t('there_were_errors', count: @check.errors.size)
|
|
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 do
|
|
redirect_to check_url(@check),
|
|
notice: t('scaffold.model_updated_successfully', model: @check.model_name.human)
|
|
end
|
|
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 do
|
|
redirect_to checks_url, notice: t('scaffold.model_destroyed_successfully', model: @check.model_name.human)
|
|
end
|
|
format.json { head :no_content }
|
|
end
|
|
end
|
|
|
|
def filter_params
|
|
@filter_params ||= params.permit(filter: %i[s level])[:filter] || {}
|
|
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(:position, :name, :success_criterion, :success_criterion_html, :level)
|
|
end
|
|
end
|