rails7的turbo_stream_from和turbo_frame_tag
来自:https://www.hotrails.dev/turbo-rails
turbo_frame_tag (单个更新)
turbo_frame_tag 会创建一个 turbo-frame的元素,包含生成的html内容,这个自定义的元素有一个唯一的id,是我们传过去的。
As we can see, the turbo_frame_tag helper creates a <turbo-frame> custom element that contains the HTML generated by the content of the block. This custom element has a unique id corresponding to the first argument we passed to the turbo_frame_tag helper.
turbo_stream_from (全部更新)
为了让我们的用户订阅 quotes 这个流,我们需要在Quotes#index页面上指定这个stream.
view: view上增加一行 turbo_stream_from "quotes"
model: after_update_commit { broadcast_replace_to "quotes" }
turbo_frame_tag (单个更新)
turbo_frame_tag 会创建一个 turbo-frame的元素,包含生成的html内容,这个自定义的元素有一个唯一的id,是我们传过去的。
As we can see, the turbo_frame_tag helper creates a <turbo-frame> custom element that contains the HTML generated by the content of the block. This custom element has a unique id corresponding to the first argument we passed to the turbo_frame_tag helper.
turbo_stream_from (全部更新)
为了让我们的用户订阅 quotes 这个流,我们需要在Quotes#index页面上指定这个stream.
view: view上增加一行 turbo_stream_from "quotes"
model: after_update_commit { broadcast_replace_to "quotes" }
加上这两条,那一个用户更新全部就一起更新了。
For our users to subscribe to the "quotes" stream, we need to specify it in the Quotes#index view. Let's add a single line of code at the top of our view:
For our users to subscribe to the "quotes" stream, we need to specify it in the Quotes#index view. Let's add a single line of code at the top of our view:
<%# app/views/quotes/index.html.erb %> <%= turbo_stream_from "quotes" %> <%# All the previous HTML markup %>
The HTML generated by the turbo_stream_from helper looks like this:
<turbo-cable-stream-source channel="Turbo::StreamsChannel" signed-stream-name="very-long-string" > </turbo-cable-stream-source>
# Remove a Turbo Frame turbo_stream.remove # Insert a Turbo Frame at the beginning/end of a list turbo_stream.append turbo_stream.prepend # Insert a Turbo Frame before/after another Turbo Frame turbo_stream.before turbo_stream.after # Replace or update the content of a Turbo Frame turbo_stream.update turbo_stream.replace
turbo_stream 可以用notice吗?
阅读量: 607
发布于:
修改于:
发布于:
修改于: