Class: ActsAsCalculatorEditor::FormulaVersionsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ActsAsCalculatorEditor::FormulaVersionsController
- Defined in:
- app/controllers/acts_as_calculator_editor/formula_versions_controller.rb
Overview
No edit, no update, no destroy โ a published version is immutable, and the corrective
action is publishing another one (docs/core-gem-contract.md ยง2.4). new accepts
?from_version_id= so "duplicate this into a new draft" is available, which is usually
what an operator reaching for "edit" actually means.
@form and @variable_rows are plain hashes rather than an unsaved FormulaVersion:
a failed submission has to come back showing exactly what the operator typed, including
the unparseable date that caused the failure, and an ActiveRecord object cannot hold one.
Constant Summary collapse
- FIELDS =
%w[expression effective_from effective_to status change_note].freeze
Instance Method Summary collapse
-
#create ⇒ Object
Straight through
PublishFormulaVersion, which is the same object the core gem's own API controller calls: the incumbent is superseded rather than rewritten, version numbers are handed out in one place, and a supersede that would leave part of the incumbent's range with no active version raisesPartialSupersedeErrorโ surfaced here as a 409 with its message intact, because that message names the exact date range at issue and the two ways out of it. - #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
Instance Method Details
#create ⇒ Object
Straight through PublishFormulaVersion, which is the same object the core gem's own
API controller calls: the incumbent is superseded rather than rewritten, version
numbers are handed out in one place, and a supersede that would leave part of the
incumbent's range with no active version raises PartialSupersedeError โ surfaced
here as a 409 with its message intact, because that message names the exact date range
at issue and the two ways out of it.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/acts_as_calculator_editor/formula_versions_controller.rb', line 39 def create @formula = formula @form = submitted_form @variable_rows = variables @active_versions = active_versions rescuing_core_errors(:new) do published = ActsAsCalculator::PublishFormulaVersion.(formula: @formula, **version_attributes) redirect_to formula_version_path(@formula, published), notice: "Published version #{published.version_number} of #{@formula.key}." end end |
#index ⇒ Object
15 16 17 18 |
# File 'app/controllers/acts_as_calculator_editor/formula_versions_controller.rb', line 15 def index @formula = formula @versions = formula.versions.includes(:variables).order(:version_number) end |
#new ⇒ Object
26 27 28 29 30 31 |
# File 'app/controllers/acts_as_calculator_editor/formula_versions_controller.rb', line 26 def new @formula = formula @form = prefilled_form @variable_rows = prefilled_variable_rows @active_versions = active_versions end |
#show ⇒ Object
20 21 22 23 24 |
# File 'app/controllers/acts_as_calculator_editor/formula_versions_controller.rb', line 20 def show @formula = formula @version = version @variables = version.variables.order(:name) end |