gpt4 book ai didi

ruby-on-rails - rails : Turbo Stream Broadcast not updating view

转载 作者:行者123 更新时间:2023-12-02 18:18:53 27 4
gpt4 key购买 nike

我有一个不更新 View 的 Turbo Stream,我不确定为什么。我在类似的配置中设置了另外两个广播,它们运行良好。

从我所见,一切看起来都应该正常工作,我只是没有在前端获得更新。我是否遗漏了一些明显的东西?

# partial
<%= turbo_stream_from 'team_players' %>
<div id="players_<%= dom_id(team)%>"
<% team.players.each do |player| %>
<%= render player %>
<% end %>
</div>
# player model
class Player < ApplicationRecord
belongs_to :team

after_create_commit do
broadcast_prepend_to(
'team_players',
target: "players_team_#{team.id}",
locals: { player: self }
)

end
end
# server log
Started GET "/cable" for 127.0.0.1 at 2022-02-16 11:45:13 +0000
Started GET "/cable/" [WebSocket] for 127.0.0.1 at 2022-02-16 11:45:13 +0000
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: keep-alive, Upgrade, HTTP_UPGRADE: websocket)
Turbo::StreamsChannel is transmitting the subscription confirmation
Turbo::StreamsChannel is streaming from team_players

# console log after manually creating a player for team 9 (exert)
...
Rendered players/_player.html.erb (Duration: 0.3ms | Allocations: 99)
[ActionCable] Broadcasting to team_players: "<turbo-stream action=\"prepend\" target=\"players_team_9\"><template><div id=\"player_1885\">\n <p>\n <strong>ID:</strong>\n 1885\n </p>\n\n <p>\n <strong>User:</strong>\n 3820748f-d9d3-400e-ac90-6149800a0e68\n </p>\n\n <p>\n <strong>Team:</strong>\n 9\n </p>\n\n <p>\n ...
=>
#<Player:0x00007fba5fa12568
...

感谢任何帮助或指点!

最佳答案

看起来好像我错过了涡轮 rails 安装过程中的第 4 步:https://github.com/hotwired/turbo-rails#installation

运行后:./bin/rails turbo:install:redis 命令行下一切正常。

如果没有这一步,事情仍然可以在单独的浏览器 session 中进行。

感谢David Colby on Twitter寻找修复。

关于ruby-on-rails - rails : Turbo Stream Broadcast not updating view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71141502/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com