Class: WorkflowInstanceBatchesController

Inherits:
ApplicationController show all
Defined in:
lib/generators/dunlop/install/workflow/templates/controllers/workflow_instance_batches_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.workflow_instance_batch_classObject



51
52
53
54
55
56
# File 'lib/generators/dunlop/install/workflow/templates/controllers/workflow_instance_batches_controller.rb', line 51

def workflow_instance_batch_class
  return @workflow_instance_batch_class if @workflow_instance_batch_class
  parts = controller_path.split('/').map(&:classify)
  parts.pop until klass = parts.join('::').safe_constantize
  @workflow_instance_batch_class = klass
end

.workflow_instance_classObject



58
59
60
61
# File 'lib/generators/dunlop/install/workflow/templates/controllers/workflow_instance_batches_controller.rb', line 58

def workflow_instance_class
  return @workflow_instance_class if @workflow_instance_class
  @workflow_instance_class = workflow_instance_batch_class.name.sub('Batch', '').constantize
end

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
# File 'lib/generators/dunlop/install/workflow/templates/controllers/workflow_instance_batches_controller.rb', line 22

def create
  @record = workflow_instance_batch_class.new(record_params)
  authorize! :manage, @record
  if @record.save
    redirect_to action: :index
  else
    render action: "new"
  end
end

#editObject



37
38
39
# File 'lib/generators/dunlop/install/workflow/templates/controllers/workflow_instance_batches_controller.rb', line 37

def edit
  authorize! :manage, @record
end

#indexObject



6
7
8
9
10
11
# File 'lib/generators/dunlop/install/workflow/templates/controllers/workflow_instance_batches_controller.rb', line 6

def index
  authorize! :read, workflow_instance_batch_class
  @q = workflow_instance_batch_class.search(params[:q])
  @q.sorts = "plan_date ASC" if @q.sorts.empty?
  @records = @q.result.page(params[:page]).per(params[:per_page])
end

#newObject



13
14
15
16
# File 'lib/generators/dunlop/install/workflow/templates/controllers/workflow_instance_batches_controller.rb', line 13

def new
  authorize! :manage, workflow_instance_batch_class
  @record = workflow_instance_batch_class.new
end

#showObject



32
33
34
35
# File 'lib/generators/dunlop/install/workflow/templates/controllers/workflow_instance_batches_controller.rb', line 32

def show
  authorize! :read, @record
  respond_with @record, record_class: workflow_instance_class, include_notes: params[:include_notes]
end

#updateObject



41
42
43
44
45
46
47
48
# File 'lib/generators/dunlop/install/workflow/templates/controllers/workflow_instance_batches_controller.rb', line 41

def update
  authorize! :manage, @record
  if @record.update record_params
    redirect_to action: :index
  else
    render action: :edit
  end
end

#with_mixed_bas_completenessObject



18
19
20
# File 'lib/generators/dunlop/install/workflow/templates/controllers/workflow_instance_batches_controller.rb', line 18

def with_mixed_bas_completeness
  @records = workflow_instance_batch_class.with_mixed_bas_load_states
end