Created
May 4, 2024 09:13
-
-
Save hungmi/b26eda8687ab1a70f184460d88e73b50 to your computer and use it in GitHub Desktop.
Turbo broadcast_*_to via ActionCable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- app/views/hello.html --> | |
<h1>Hello!</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/hello_controller.rb | |
class HelloController < ApplicationController | |
def create | |
Turbo::StreamsChannel.broadcast_append_to( | |
@resource.id, | |
:hello, | |
target: 'hello-turbo-frame', | |
template: 'hello', | |
layout: false | |
) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- app/views/resources/show.html.erb --> | |
<%= turbo_stream_from @resource.id, :hello %> | |
<turbo-frame id="hello-turbo-frame"></turbo-frame> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment