1

Given the following

<%= turbo_frame_tag dom_id(@item, "loader_helper"), src: home_index_path(@item) %>

This code will trigger with page load other request to specified controller

Started GET "/home/1" for ::1 at 2023-01-23 16:10:39 +0300
Processing by HomeController#index as HTML

The problem is that I want to render not HTML, but rather turbo_stream format with some page modifications and don't rely on some JS solution.

So I would expect the following pseudocode to work

<%= turbo_frame_tag dom_id(@item, "loader_helper"), src: home_index_path(@item), format: :turbo_stream %>

to load action like so

Started GET "/home/1" for ::1 at 2023-01-23 16:10:39 +0300
Processing by HomeController#index as TURBO_STREAM

and then in controller I can handle it with specific formats

..
def index
  respond_to do |format|
    format.html
    format.turbo_stream
  end
end

Are there any workarounds? Or this is intended by design, so we won't be able to trigger turbo_stream on page load (you can do it with js easily), and manipulate with some HTML.

zhisme
  • 2,368
  • 2
  • 19
  • 28
  • My two cents: would the format not be part of the url, rather than an option to the turbo frame tag, like this: `my_path(whatever, format: turbo_stream)`. Also there is a specific data attribute if you want to trigger turbo stream with GET methods : `data-turbo-stream="true"` . Though not sure it can be appended to a turbo frame. – Maxence Jan 23 '23 at 13:29
  • 1
    @Maxence, data-turbo-stream didn't work, however moving format to part of url so `src: home_path(item, format: :turbo_stream)` did work expected way. Thank you! – zhisme Jan 23 '23 at 14:22

1 Answers1

2

Based on the doc https://turbo.hotwired.dev/handbook/streams it injects text/vnd.turbo-stream.html for POST, PUT, PATCH, or DELETE HTTP method. If you want to use it for the GET method, you must add the data-turbo-stream attribute. So for your case, you can try the following code:

<%= turbo_frame_tag dom_id(@item, "loader_helper"), src: home_index_path(@item, format: :turbo_stream) %>

Reference: https://github.com/hotwired/turbo-site/pull/40#discussion_r570471371

Saiqul Haq
  • 2,287
  • 16
  • 18