How to wrap a table row with a turbo frame?

I ended up doing this and it solves the problem.

Add an id to tbody:

    # index.html.eb
    <tbody id="exercises">
         <%= render @exercises %>
    </tbody>

Make some changes to # _exercise.html.erb

<%= content_tag :tr, id: dom_id(exercise) do %>
        <td><%= exercise.name %></td>
        <td><%= exercise.description %></td>
        <td><%= link_to exercise.video_url, exercise.video_url %></td>
        <td><%= link_to 'Show', exercise %></td>
        <td><%= link_to 'Edit', edit_exercise_path(exercise) %></td>
        <td><%= link_to 'Destroy', exercise, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<% end %>

Create a new file # views/exercises/create.turbo_stream.erb

<% turbo_stream.append 'exercises', @exercise %>

It should now working.

2 Likes