Files
simple-aircraft-manager-rails/app/controllers/loading_setups_controller.rb
T
rickyandClaude Opus 5.5 c822bda779 CG envelope can be entered as moment (lb-in/1000)
As POH moment-envelope charts and Garmin Pilot give it. Stored as CG
inches (moment x 1000 / weight), shown back as entered with the CG next
to each point; switching the units and saving re-reads the numbers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 14:42:44 -05:00

23 lines
874 B
Ruby

# The aircraft's loading stations (arms) and CG envelope, from the POH, for
# the loading calculator.
class LoadingSetupsController < ApplicationController
include AircraftScoped
before_action :require_owner!
def edit
@setup = @aircraft.loading_setup
end
def update
permitted = params.fetch(:setup, {}).permit(:fuel_lb_per_gal, :envelope_unit, stations: %i[name arm max fuel], envelope: %i[weight cg])
@setup = LoadingSetup.from_params(permitted.to_h)
if @setup.valid?
@aircraft.update!(loading_stations: @setup.stations_json, cg_envelope: @setup.envelope.map { |w, cg| [ w.to_f, cg.to_f ] })
log_event("aircraft", "Loading stations and CG envelope updated")
redirect_to aircraft_weight_balance_records_path(@aircraft), notice: "Loading setup saved."
else
render :edit, status: :unprocessable_entity
end
end
end