Files
simple-aircraft-manager-rails/app/controllers/inspection_records_controller.rb
T
rickyandClaude Opus 5.5 a4b72cf2c1 Part 91 inspection rules: limitations, annual as 100-hour, overrun, clock
- Inspection types say what overdue means: grounds the aircraft, no IFR
  (91.411), no transponder (91.413) or advisory. Overdue limitations show
  as a new LIMITED status ("VFR only", "No transponder") and don't block
  flights under airworthiness enforcement
- "Also counts as": an annual satisfies the 100-hour (91.409(b))
- Overrun allowance: a 100-hour done within 10 hrs of due counts the next
  one from when it was due; done early, from when it was done
- Per-aircraft maintenance clock (tach or Hobbs) for time in service; new
  records default to it (fixes the tach-offset mismatch)
- Status labels Current / Due soon / limitation / Grounded, with the
  91.7 pilot-in-command note
- Migration converts existing types by name; archives carry the new fields

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 10:04:46 -05:00

52 lines
1.9 KiB
Ruby

class InspectionRecordsController < ApplicationController
include AircraftScoped
before_action :require_owner!
before_action :set_record, only: %i[edit update destroy]
def new
@record = InspectionRecord.new(aircraft: @aircraft, date: Date.current,
aircraft_hours: @aircraft.current_hours,
inspection_type_id: params[:inspection_type_id])
end
def create
@record = InspectionRecord.new(record_params.merge(aircraft: @aircraft))
if @record.save
log_event("inspection", "Inspection completed: #{@record.inspection_type.name}")
redirect_to aircraft_inspections_path(@aircraft), notice: "Inspection recorded."
else
render :new, status: :unprocessable_entity
end
end
def edit; end
def update
if @record.update(record_params)
log_event("inspection", "Inspection record updated: #{@record.inspection_type.name}")
redirect_to aircraft_inspections_path(@aircraft), notice: "Inspection record updated."
else
render :edit, status: :unprocessable_entity
end
end
def destroy
@record.destroy!
log_event("inspection", "Inspection record deleted: #{@record.inspection_type.name}")
redirect_to aircraft_inspections_path(@aircraft), notice: "Inspection record deleted."
end
private
def set_record = @record = InspectionRecord.for_aircraft(@aircraft).find(params[:id])
def record_params
p = params.require(:inspection_record).permit(:inspection_type_id, :date, :aircraft_hours, :notes,
:logbook_entry_id, :component_id)
p[:inspection_type_id] = scoped_id(@aircraft.applicable_inspection_types, p[:inspection_type_id])
p[:logbook_entry_id] = scoped_id(@aircraft.logbook_entries, p[:logbook_entry_id])
p[:component_id] = scoped_id(@aircraft.components, p[:component_id])
p
end
end