Rails, turbo frame, flash and tooltips

Here’s what I’m thinking, real quick (I might have better ideas later):

  1. In the turbo_frame that has the like button, you’ll have a button that posts the “like” and the resulting page will have the updated “like” turbo_frame. That will update that portion of the page automatically.
  2. For the tooltip, you’ll want to wrap that component in a Stimulus controller that properly wires up the $(element).tooltip() on connect() and properly dismounts the tooltip on disconnect().
  3. To update another part of the page with a flash message, instead of returning a format.turbo_stream, you can manually return a turbo_stream.replace tag as part of your updated turbo_frame. Include the notice inside the turbo_stream.replace and have it target the #notices div elsewhere on the page.
<%= turbo_frame_tag dom_id(@like) do %>
  <!-- The Like HTML -->
  <% if notice.present? %>
    <%= turbo_stream.replace "#notices" do %>
      <!-- new notices go here -->
    <% end %>
  <% end %>
<% end %>
2 Likes