[英]turbo_frame_tag request with other formats than HTML
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此代码将触发页面加载其他请求到指定的 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.问题是我想呈现的不是 HTML,而是带有一些页面修改的 turbo_stream 格式,并且不依赖于某些 JS 解决方案。
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然后在 controller 中我可以用特定的格式处理它
..
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.
或者这是设计使然,因此我们将无法在页面加载时触发 turbo_stream(您可以使用 js 轻松完成),并使用一些 HTML 进行操作。
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.基于文档https://turbo.hotwired.dev/handbook/streams ,它为 POST、PUT、PATCH 或 DELETE HTTP 方法注入
text/vnd.turbo-stream.html
。 If you want to use it for the GET method, you must add the data-turbo-stream
attribute.如果要将其用于 GET 方法,则必须添加
data-turbo-stream
属性。 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参考: https://github.com/hotwired/turbo-site/pull/40#discussion_r570471371
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.