All threads / cancel actioncable connection for unauthorized users?
Ask A Question


You’re not receiving notifications from this thread.

cancel actioncable connection for unauthorized users?

Matt Taylor asked in Rails

Followed the series on action cable notifications and setup the meta tag so that action would not try to connect if the meta tag was present. Here is my code.

$(document).on("turbolinks:load", function () {
  if ($("meta[name='current_user']").length > 0) {
    App.activity_feed = App.cable.subscriptions.create("ActivityFeedChannel", {
    connected: function() {console.log("I connected")},
    disconnected: function() {console.log("I disconnected")},
    received: function(data) {

I tried it with and without the turbolinks code as well.. no dice.
I look in the dev tools and see that the meta tag is present and when I run $("meta[name='current_user']").length > 0 in the console it comes back as true.

Not sure what i'm missing. If i get rid of the if statment actioncable connects successfully.

Thanks for the help.

Join the discussion

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

Join 70,078+ 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.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.