Class: ActsAsCalculator::FormulasController

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

Overview

Identity only — key, scope, owner. Everything that can change about a formula is a version, which is why there is a separate controller for those.

Instance Method Summary collapse

Instance Method Details

#createObject



15
16
17
18
19
# File 'app/controllers/acts_as_calculator/formulas_controller.rb', line 15

def create
  created = Formula.create!(**formula_attributes)

  render json: { formula: SerializeFormula.(formula: created) }, status: :created
end

#destroyObject



27
28
29
30
31
# File 'app/controllers/acts_as_calculator/formulas_controller.rb', line 27

def destroy
  formula.destroy!

  head :no_content
end

#indexObject



7
8
9
# File 'app/controllers/acts_as_calculator/formulas_controller.rb', line 7

def index
  render json: { formulas: scoped_formulas.map { |formula| SerializeFormula.(formula:) } }
end

#showObject



11
12
13
# File 'app/controllers/acts_as_calculator/formulas_controller.rb', line 11

def show
  render json: { formula: SerializeFormula.(formula:, versions: true) }
end

#updateObject



21
22
23
24
25
# File 'app/controllers/acts_as_calculator/formulas_controller.rb', line 21

def update
  formula.update!(**formula_attributes)

  render json: { formula: SerializeFormula.(formula:) }
end