Add Vehicle from an appointment sets it there and returns

The appointment page's Add Vehicle link (shown when the appointment has none)
now carries the appointment and a back_url. Creating the vehicle calls a new
:controller_vehicles_new_after_save hook; this plugin's listener sets the
vehicle on that appointment (same customer, no vehicle yet, user may edit
appointments) and the form redirects back to the appointment. The calendar
plugin is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
Claude committed 2026-11-01 13:11:41 -05:00
1 parent fae397adac
commit 53991ed087
7 files changed
+57 -6

No files matched your search

+5 -1
View File
@@ -47,7 +47,11 @@ class VehiclesController < ApplicationController
if @vehicle.save
flash[:notice] = t :notice_vehicle_created
redirect_to @vehicle
# For whatever the vehicle was added from (e.g. an appointment, which then gets this vehicle: see
# Vehicles::Hooks::AppointmentVehicleHookListener). Context: params, vehicle
call_hook(:controller_vehicles_new_after_save, params: params, vehicle: @vehicle)
# Back to where the vehicle was added from (back_url), else the vehicle
redirect_back_or_default @vehicle
else
# A duplicate VIN: point to the vehicle that already has it
@existing_vehicle = Vehicle.find_by(vin: @vehicle.vin) if @vehicle.errors.of_kind?(:vin, :taken)