This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2021-02-21 10:50:12 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Admin
|
|
|
|
class RulesController < BaseController
|
|
|
|
before_action :set_rule, except: [:index, :create]
|
|
|
|
|
|
|
|
def index
|
|
|
|
authorize :rule, :index?
|
|
|
|
|
|
|
|
@rules = Rule.ordered
|
|
|
|
@rule = Rule.new
|
|
|
|
end
|
|
|
|
|
2023-04-29 21:46:39 -07:00
|
|
|
def edit
|
|
|
|
authorize @rule, :update?
|
|
|
|
end
|
|
|
|
|
2021-02-21 10:50:12 -08:00
|
|
|
def create
|
|
|
|
authorize :rule, :create?
|
|
|
|
|
|
|
|
@rule = Rule.new(resource_params)
|
|
|
|
|
|
|
|
if @rule.save
|
|
|
|
redirect_to admin_rules_path
|
|
|
|
else
|
|
|
|
@rules = Rule.ordered
|
|
|
|
render :index
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
authorize @rule, :update?
|
|
|
|
|
|
|
|
if @rule.update(resource_params)
|
|
|
|
redirect_to admin_rules_path
|
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
authorize @rule, :destroy?
|
|
|
|
|
|
|
|
@rule.discard
|
|
|
|
|
|
|
|
redirect_to admin_rules_path
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_rule
|
|
|
|
@rule = Rule.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def resource_params
|
|
|
|
params.require(:rule).permit(:text, :priority)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|