Ask A Question

Notifications

You’re not receiving notifications from this thread.

Realtime browser updates with Cable Ready Discussion

Great episode.

Just as a note to anybody watching this who might be wondering, cable_ready pairs perfectly well with Stimulus Reflex as well. You can simply include the cable_ready call in your *_reflex.rb file and it will cause the reflex change to be broadcast out to every connected client at the same time as the reflex (technically right before, but close enough).

Reply

This is so much easier to implement compared to using a front end framework like React. I wish I knew about these concepts earlier!

Reply

Is there a way to create a channel that only broadcasts to a specific signed in user? For example just send the broadcast to the user who created the card instead of everyone currently connected to the application?

Reply

Sure, this can be done in my different ways. You could include a "data-user-id='#{current_user.id}'" in your template and set the selector option in your cable_ready call to be "[data-user-id='#{current_user.id}']".

This would work, but if your use case is to only update to the current user, Stimulus Reflex does that out of the box.

Reply

Thanks Michael.

It also looks like I can do this by including the user id in the stream name as well and it will only send the update to any connections that user has.

class UserChannel < ApplicationCable::Channel
def subscribed
stream_for "user_channel_#{current_user.id}"
end
end

cable_ready["user:user_channel_#{user_id}"].inner_html(
selector: "#update_div",
html: html
)
cable_ready.broadcast

Reply

Hi! Is there anyone can help me?
I was trying implement the cable_ready by following this tutorial. But unfortunately, the cable_ready didn't work well. It just broadcast the data, but the client didn't receive that data. I also tried cloning the repo from this tutorial to my local machine, it also didn't work. Idk why, I'm still figuring it out.

Reply

facing a similar issue.. its broadcasting the data, but not updating the views. wondering if I'm doing something wrong related to action cable. were you able to fix yours?

Reply

had to change my cable.yml file to the below and its working fine.

development:
  adapter: redis
  url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>

test:
  adapter: async

production:
  adapter: redis
  url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
Reply

I have an application using ActionCable broadcasting to about 100 TV screens when a new event happens.
This works great on local machine but on server (centOS, NGINX) I see a lot of Broken Pipe messages and many screens don't receive the updates.
Would this be a better solution or have the same problem since it's using the same technology under the hood? Please advice

Reply

Hi Peter, I'd be happy to discuss the probems that you're seeing and make some suggestions about how best to proceed.

CableReady is based ActionCable, which should be able to scale to ~4000 concurrent connections. There are other solutions beyond that stage.

Just jump on the #cableready channel on the StimulusReflex Discord: https://discord.gg/XveN625

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.