Simon Moro PRO said over 1 year ago on Diving into Hotwire :
This is great. I especially loved the walkthrough of the tasks... The Asset Pipeline has been doing my head in ever since Webpacker - seeing how the tasks include javascript files was very helpful :) Thanks!

Tiago Ameller PRO said over 1 year ago on Diving into Hotwire :
I'm confused about this back to the Asset Pipeline. I've made a lot of work migrating my apps to Webpacker, (BTW it was not so easy). For a new Rails 6 project, what do you think is the right approach: Asset Pipeline or Webpacker?

David Kimura PRO said over 1 year ago on Diving into Hotwire :
  Tiago Ameller I think that keeping things in webpacker right now is not a mistake. One nice thing about the webpacker approach is that things can be kept really isolated. Personally, I'm going to keep using webpacker since I've not experienced any issues with it that haven't been relatively easy to resolve.

When I tried creating a new Rails application where with Turbo and with the Asset Pipeline, there were complications with getting libraries to load in properly. Especially in scenarios where I wanted to just do an import on a JS library like FullCalendar and have things work smoothly.

ajmaseda PRO said over 1 year ago on Diving into Hotwire :
Can this be edited

ternggio95 said 12 months ago on Diving into Hotwire :
How to update <%= @products.count %> with turbo stream when a new product is created?

David Kimura PRO said 12 months ago on Diving into Hotwire :
  ternggio95 Have a look at the source https://github.com/hotwired/turbo-rails/blob/main/app/models/concerns/turbo/broadcastable.rb on the broadcast methods. At the top, there is a bit where they show a callback to then trigger a broadcast.

after_create_commit :broadcast_later


def broadcast_later
  broadcast_prepend_later_to examiner.identity, :clearances

Since you will want to update a count, you would likely want to replace instead of prepend. The broadcast_replace_to would likely be what you would want. However, if there are a lot of users, you may want to do this in a background job with broadcast_replace_later_to instead. It looks like this allows you to specify a partial as well as the local variables which in your case would be the product count..

# Replace this broadcastable model in the dom for subscribers of the stream name identified by the passed
# <tt>streamables</tt>. The rendering parameters can be set by appending named arguments to the call. Examples:
#   # Sends <turbo-stream action="replace" target="clearance_5"><template><div id="clearance_5">My Clearance</div></template></turbo-stream>
#   # to the stream named "identity:2:clearances"
#   clearance.broadcast_replace_to examiner.identity, :clearances
#   # Sends <turbo-stream action="replace" target="clearance_5"><template><div id="clearance_5">Other partial</div></template></turbo-stream>
#   # to the stream named "identity:2:clearances"
#   clearance.broadcast_replace_to examiner.identity, :clearances, partial: "clearances/other_partial", locals: { a: 1 }
def broadcast_replace_to(*streamables, **rendering)
  Turbo::StreamsChannel.broadcast_replace_to *streamables, target: self, **broadcast_rendering_with_defaults(rendering)

Login to Comment