Class: CalculationController

Inherits:
ApplicationController show all
Defined in:
app/controllers/calculation_controller.rb

Overview

The main controller for performing calculations in a question by question manner.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#formNilForm, ...

The form to use to capture the input data


36
37
38
# File 'app/controllers/calculation_controller.rb', line 36

def form
  @form ||= form_class.new
end

Instance Method Details

#current_calculationCalculation

The current calculation from the session converted into a @see Calculation instance


28
29
30
# File 'app/controllers/calculation_controller.rb', line 28

def current_calculation
  @current_calculation ||= Calculation.new(session.fetch(:calculation) { {} }.symbolize_keys)
end

#editObject


21
22
23
# File 'app/controllers/calculation_controller.rb', line 21

def edit
  self.form = form_class.new_ignoring_extras(current_calculation.inputs)
end

#homeObject


6
7
8
# File 'app/controllers/calculation_controller.rb', line 6

def home
  session.delete(:calculation)
end

#updateObject

(PATCH | PUT) /calculation


11
12
13
14
15
16
17
18
19
# File 'app/controllers/calculation_controller.rb', line 11

def update
  self.form = form_class.new(calculation_params.to_h)
  if form.valid?
    submit_service = calculate
    redirect_to next_url(submit_service)
  else
    render :edit
  end
end