Welcome

CableReady completes the ActionCable story and expands the utility of web sockets in your Rails app

GitHub stars GitHub forks Twitter follow

Why CableReady?

CableReady helps you create great real-time user experiences by making it simple to trigger client-side DOM changes from server-side Ruby. It establishes a standard for interacting with the client via ActionCable web sockets. No need for custom JavaScript.

Possible interactions range from updating a single element's value to replacing entire sections of content. You can even dispatch client-side DOM events from the server. Also, updates don't need to be initiated by the user. For example, CableReady can update your UI in response to things happening on the server, such as long running ActiveJobs or activity from API calls and webhooks. It's never been easier to notify users of site wide activity.

How does it work?

CableReady builds on top of ActionCable and allows you to emit DOM instructions from the server that are automatically executed on the client. It expands the role of web sockets in the Rails ecosystem and elevates Rails as a viable highly performant alternative to the Single Page App.

Learn more about ActionCable to help you get the most out of CableReady.

What can I do with it?

CableReady supports the following DOM operations that can be triggered from server-side Ruby code.

  1. morph

  2. innerHTML

  3. outerHTML

  4. remove

  5. setValue

  6. setStyle

  7. setStyles

  8. setCookie

As with other new tools, the potential use cases are only limited by your imagination. For example, CableReady provides the foundation for incredible libraries like StimulusReflex.

Can I see an example?

This is a simple example that demonstrates how to set an element's value.

cable_ready["MyChannel"].set_value(
selector: "#my-element",
value: "A new value from the server"
)
cable_ready.broadcast

In this example, all clients connected to MyChannel will receive the broadcast and will update the DOM element to the new value.