instance method
turbo_stream_from
Ruby on Rails 1.5.0
Since v1.3.3 Last seen in v2.0.23Signature
turbo_stream_from(*streamables, **attributes)
Used in the view to create a subscription to a stream identified by the streamables running over the Turbo::StreamsChannel. The stream name being generated is safe to embed in the HTML sent to a user without fear of tampering, as it is signed using Turbo.signed_stream_verifier. Example:
# app/views/entries/index.html.erb <%= turbo_stream_from Current.account, :entries %> <div id="entries">New entries will be appended to this target</div>
The example above will process all turbo streams sent to a stream name like account:5:entries (when Current.account.id = 5). Updates to this stream can be sent like entry.broadcast_append_to entry.account, :entries, target: "entries".
Custom channel class name can be passed using :channel option (either as a String or a class name):
<%= turbo_stream_from "room", channel: RoomChannel %>
It is also possible to pass additional parameters to the channel by passing them through data attributes:
<%= turbo_stream_from "room", channel: RoomChannel, data: {room_name: "room #1"} %>
Parameters
-
streamablesrest -
attributeskeyrest
Source
# File app/helpers/turbo/streams_helper.rb, line 52
def turbo_stream_from(*streamables, **attributes)
attributes[:channel] = attributes[:channel]&.to_s || "Turbo::StreamsChannel"
attributes[:"signed-stream-name"] = Turbo::StreamsChannel.signed_stream_name(streamables)
tag.turbo_cable_stream_source(**attributes)
end
Defined in app/helpers/turbo/streams_helper.rb line 52
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Turbo::StreamsHelper