Files
simple-aircraft-manager-rails/app/controllers/consumable_records_controller.rb
T
rickyandClaude Opus 5.5 89ed0a76f9 Move all user-facing text into config/locales/en.yml for localization
- Views use lazy t(".key") lookups; sentences with values or links stay
  whole (interpolation, _html keys); counts use one/other plurals
- Stored-value labels (statuses, types, priorities...) are LabelSets read
  from labels: in the current locale; field names and validation messages
  under activerecord:; flash and activity text under flash:
- Services, models, helpers, mailer subjects, the logbook PDF, procedures
  templates, records package README and transcription warnings localized;
  the PDF reuses LogbookEntry#certification_statement instead of a copy
- Scripts read js: strings from a JSON tag via app/javascript/i18n.js
- Dates through I18n.l (app, weekday, month_year, long formats); html lang
  follows the locale
- APP_LOCALE picks the language (falls back to English); missing
  translations raise in development and tests
- README: Translating section and APP_LOCALE

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 22:08:20 -05:00

63 lines
2.6 KiB
Ruby

class ConsumableRecordsController < ApplicationController
include AircraftScoped
before_action :require_owner!, only: %i[edit update destroy]
before_action :set_record, only: %i[edit update destroy]
RECORDS_PER_PAGE = 50
# Records a page at a time; the rest load as you scroll (each page ends in
# a lazy frame that fetches the next). The charts cover everything.
def index
@page = [ params[:page].to_i, 1 ].max
rows = @aircraft.consumable_records.recent_first.offset((@page - 1) * RECORDS_PER_PAGE).limit(RECORDS_PER_PAGE + 1).to_a
@more = rows.size > RECORDS_PER_PAGE
@records = rows.first(RECORDS_PER_PAGE)
return render(partial: "consumable_records/records", locals: { records: @records, page: @page, more: @more }) if turbo_frame_request?
@oil = ConsumptionStats.new(@aircraft, "oil")
@fuel = ConsumptionStats.new(@aircraft, "fuel")
end
def new
type = params[:type].in?(ConsumableRecord::TYPES.keys) ? params[:type] : "oil"
@record = @aircraft.consumable_records.new(record_type: type, date: Date.current,
flight_hours: @aircraft.tach_time)
end
def create
@record = @aircraft.consumable_records.new(record_params)
if @record.save
log_event(@record.record_type, t("flash.consumable_records.added_event", type: ConsumableRecord::TYPES[@record.record_type], quantity: @record.quantity_added, unit: @record.unit))
redirect_to aircraft_consumable_records_path(@aircraft), notice: t("flash.consumable_records.record_added")
else
render :new, status: :unprocessable_entity
end
end
def edit; end
def update
if @record.update(record_params)
log_event(@record.record_type, t("flash.consumable_records.updated_event", type: ConsumableRecord::TYPES[@record.record_type]))
redirect_to aircraft_consumable_records_path(@aircraft), notice: t("flash.consumable_records.record_updated")
else
render :edit, status: :unprocessable_entity
end
end
def destroy
@record.destroy!
log_event(@record.record_type, t("flash.consumable_records.deleted_event", type: ConsumableRecord::TYPES[@record.record_type]))
redirect_to aircraft_consumable_records_path(@aircraft), notice: t("flash.consumable_records.record_deleted")
end
private
def set_record = @record = @aircraft.consumable_records.find(params[:id])
def record_params
params.require(:consumable_record).permit(:record_type, :date, :quantity_added, :level_after,
:consumable_type, :flight_hours, :notes, :excluded_from_averages)
end
end