This project demonstrates how to integrate the Rage framework with Datastar using the official Ruby SDK.
bundle install
rage sVisit http://localhost:3000.
The integration consists of two files:
Configures the Datastar SDK for Rage:
-
Finalizer: Sets a custom finalizer that stores the response on the view context instead of rendering immediately. This is necessary because the SDK allows multiple
datastream.streamcalls per action, and each call triggers the finalizer. Rendering directly would cause a "Render was called multiple times" error. -
Executor: Defines a custom executor that uses Fibers instead of threads, aligning with Rage's fiber-based concurrency model.
A controller concern that:
- Exposes a
datastarhelper to access the Datastar object. - Provides a
datastar_response=writer used by the finalizer. - Defines an
around_actionthat waits for the action to complete, then renders the accumulated SSE response using Rage'srender sse:.