Autosave drafts with Stimulus + Turbo (lightweight)

10726
0

For long text entry, autosave is a huge quality-of-life improvement. I implement it with a Stimulus controller that debounces input and submits the form to a drafts endpoint in the background. The response is a turbo stream that updates a “Saved at …” indicator. This is intentionally lightweight: I don’t try to sync every keystroke or build conflict resolution. The draft record is the source of truth and can be resumed later. Turbo makes the submission easy; you still get CSRF handling and standard Rails routing. I keep autosave optional and resilient: if the request fails, it doesn’t block typing, and the UI can show “Offline” or “Not saved”. This approach gives 80% of the benefit with 20% complexity.