All threads / cancel actioncable connection for unauthorized users?

Ask A Question

Notifications

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) {
      $("#completed-timeline-ul").prepend(data.html);
    }
    });
  };
});

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 37,344+ 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.