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.

Reply
Join the discussion
Create an account Log in

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

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

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