I have Hotwire setup in my Rails app, but it doesn't update the index view with projects. I have a simple projects view:
<div>
<ul role="list" class="mt-1 grid grid-cols-1 gap-1">
<%= turbo_stream_from "projects" %>
<%= turbo_frame_tag "projects" do %>
<%= render @projects %>
<% end %>
</ul>
</div>
There is a projects/_project.html.erb
partial, which just shows the individual project with a turbo frame:
<%= turbo_frame_tag dom_id(project) do %>
<p><%= project.name %></p>
<p><%= project.status %></p>
<% end %>
In the project
model I added the stream:
after_create_commit { broadcast_append_to 'projects' }
after_update_commit { broadcast_replace_to 'projects' }
after_destroy_commit { broadcast_remove_to 'projects' }
Now when I add a project in the console, I see it is broadcasting:
[ActionCable] Broadcasting to projects: "<turbo-stream action=\"append\" target=\"projects\"><template> <turbo-frame id=\"project_9\">\n <li ... </li>\n</turbo-frame></template></turbo-stream>"
But in the view in the browser the project is not added. Only after a browser page refresh the project is shown.
It seems the broadcasting itself is fine, but that Rails doesn't know where to append the new project.
What is wrong?