All threads / Reopen ActionCable after login?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Reopen ActionCable after login?

Marcus S asked in Rails

Hey Folks,

I'm currently using Jumpstart and Stimulus Reflex.

After logging in, I am getting an error in the Browser's JS console:

The ActionCable connection is not open! `this.isActionCableConnectionOpen()` must return true before calling `this.stimulate()`

If I refresh the page (after being logged in), the websocket opens and all is good.

Is there a way I can reopen the ActionCable websocket after logging in?

Cheers,

Marcus

Jumpstart modifies form submits to be AJAX requests using turbolinks_render.

Your default Rails form submission is a POST request, so the page would fully reload and ActionCable would connect.

I never thought about it, but that is probably something that can/should be triggered after login. A Stimulus controller for this would make sense. It can just check fi the connection is open and, if not, issue the connect. It would probably need to be on every page, unless there's a way to do it after login. I need to think on a good way to do that.

So, just tested this as I added multitenancy to ActionCable in Jumpstart Pro. I confirmed that ActionCable will attempt to connect automatically after you login because of the NotificationsChannel we added.

You can also call consumer.connection.open() anytime to connect.

Fantastic, thanks for the tip Chris!

Cheers,

Marcus

Join the discussion

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.