Class: Admin::BusinessRulesController

Inherits:
BaseController
  • Object
show all
Defined in:
lib/generators/open_loam/install/templates/admin/business_rules_controller.rb

Overview

Managing business rules (OpenLoam::BusinessRule) — manager-only, since a rule can notify, emit events, and set fields across the tenant. The condition and actions are edited as JSON for the prototype (a visual builder is a future increment). The recent execution log shows WHY rules fired.

Constant Summary

Constants included from Pagination

Pagination::PER_PAGE

Instance Method Summary collapse

Methods inherited from BaseController

skip_authorization!

Methods included from Pagination

#paginate

Instance Method Details

#create ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/generators/open_loam/install/templates/admin/business_rules_controller.rb', line 25

def create
  @rule = OpenLoam::BusinessRule.new(rule_params)
  if @rule.save
    redirect_to admin_business_rules_path, notice: "Rule created."
  else
    render :new, status: :unprocessable_entity
  end
end

#destroy ⇒ Object



44
45
46
47
# File 'lib/generators/open_loam/install/templates/admin/business_rules_controller.rb', line 44

def destroy
  @rule.destroy!
  redirect_to admin_business_rules_path, notice: "Rule deleted."
end

#edit ⇒ Object



34
# File 'lib/generators/open_loam/install/templates/admin/business_rules_controller.rb', line 34

def edit; end

#index ⇒ Object



16
17
18
19
# File 'lib/generators/open_loam/install/templates/admin/business_rules_controller.rb', line 16

def index
  @rules = OpenLoam::BusinessRule.by_priority
  @recent_runs = OpenLoam::BusinessRuleRun.recent.limit(20)
end

#new ⇒ Object



21
22
23
# File 'lib/generators/open_loam/install/templates/admin/business_rules_controller.rb', line 21

def new
  @rule = OpenLoam::BusinessRule.new(active: true, condition: {}, actions: [])
end

#update ⇒ Object



36
37
38
39
40
41
42
# File 'lib/generators/open_loam/install/templates/admin/business_rules_controller.rb', line 36

def update
  if @rule.update(rule_params)
    redirect_to admin_business_rules_path, notice: "Rule updated."
  else
    render :edit, status: :unprocessable_entity
  end
end