DEV Community

Discussion on: Real-Time Partial Updates in Ruby on Rails using hotwire-rails

Collapse
 
rusty_sys_dev profile image
Scott

In a manner of speaking I assume that the turbo_stream_from subscribes to the Posts ApplicationRecord's broadcast_to?

Additionally is @posts available to the view because of the broadcast, or are you just not showing your method implementations?

Collapse
 
mikerogers0 profile image
Mike Rogers ✈️

In a manner of speaking I assume that the turbo_stream_from subscribes to the Posts ApplicationRecord's broadcast_to?

Close! Theturbo_stream_from :posts tells the users Browser to subscribe to :posts stream (It just adds a snippet of HTML to the page) & in the Post model we're telling it to broadcast to the:posts stream.

Additionally is @posts available to the view because of the broadcast,

I didn't post up the code controller action where I set that, I'll aim to do a more in depth write up in the future. The broadcast method passes the current model to app/views/posts/_post.html.erb as the post value.

Collapse
 
rusty_sys_dev profile image
Scott

Thanks! That clarifies things a lot!

Ill keep my fingers crossed and an eye out for your detailed write up!