Hotwire

Terms

Hotwire consists of Turbo, a library that manages user navigation and communication with the server without needing custom JavaScript, and Stimulus, which supports client-side interactions written in JavaScript. Stimulus is designed to be written as an extension to the HTML markup you are already writing and is well suited to small interactions that don’t need to manage a lot of state, or where the majority of the state is managed by the server application. A third tool, Strada, which manages interactions with native mobile devices, has not yet been released as I write this.

Excerpt From Modern Front-End Development for Rails, Second Edition

Working with JavaScript in Rails

Single

respond_to do |format|
  format.turbo_stream do
    render turbo_stream: turbo_stream.replace(
      :container_id,
      partial: "path/to/partial",
      locals: {key: value}
    )
  end
  format.html {...}
  format.json {...}
end

Multiple

create.turbo_stream.erb

<%= turbo_stream.replace 'notice' do %>
  <%= render partial: 'store/notice', locals: {notice: @notice} %>
<% end %>

<%= turbo_stream.replace 'cart' do %>
  <%= render partial: 'layouts/cart', locals: {cart: @cart} %>
<% end %>

Action Cable

(hard to summarize)