Home > Net >  GET request processed as HTML rather than TURBO_STREAM from within turbo_frame_tag
GET request processed as HTML rather than TURBO_STREAM from within turbo_frame_tag

Time:12-20

I am starting to work with hotwire/turbo and have set everything up. Turbo streams are working correctly.

Within index.html.erb:

<h1>Tasks</h1>
<%= turbo_stream_from "tasks" %>

<div id="tasks">
  <% @tasks.each do |task| %>
    <%= render task %>
  <% end %>
</div>

Within _task.html.erb

<%= turbo_frame_tag dom_id(task) do %>
  <%= link_to 'Edit', edit_task_path(task) %>
  <%= link_to 'Destroy', task, method: :delete, data: { confirm: 'Are you sure?' } %>
  <hr>
<% end %>

When the destroy button is pressed as expected, rails console says:

Started DELETE "/tasks/41" for ::1 at 2021-12-14 18:40:32  0000
Processing by TasksController#destroy as TURBO_STREAM

But when pressing the edit button, rails console says:

Started GET "/tasks/41/edit" for ::1 at 2021-12-14 18:41:29  0000
Processing by TasksController#edit as HTML

This means the page loads a new page, rendering edit.html.erb rather than just updating the content within the turbo_frame_tag.

When inspecting the DOM, both the edit and destroy links are within a turbo-frame:

<turbo-frame id="task_41">
  <a href="/tasks/41/edit">Edit</a>
  <a data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/tasks/41">Destroy</a>
  <hr>
</turbo-frame> 

So my question is, why does the request get processed as HTML and not TURBO_STREAM ?

edit.html.erb looks like this:

<h1>Editing Task</h1>
<%= turbo_frame_tag dom_id(@task) do %>
    <%= render 'form', task: @task %>
<% end %>
<%= link_to 'Show', @task %> |
<%= link_to 'Back', tasks_path %>

Thanks very much!

CodePudding user response:

Solved:

In application.js, I still had this line:

require("turbolinks").start()

I removed this, which fixed the problem.

  • Related