Disabling ActionCable for Unauthenticated Users Discussion
Hey Chris,
I tried to integrate the meta tag if else statement into the group chat app in the channels/chatrooms.js and got "cannot read property `send_message` of undefined" error. It was surprising since if I checked the val of the meta length it returned 1. It took some time to realize that you have to wrap this code into a `turbolinks:load` event since when the code gets to that point when send_message is invoked the meta tag length value is still 0.
in js files:
$(document).on("turbolinks:load", function () {
if ($("meta[name='current-user']").length >0) {
[...]
}
});
in coffee files:
$(document).on 'turbolinks:load', ->
**if $("meta[name='current-user']").length >0
[...]
(the ** only indicate mandatory indentation - they need to be removed and replaced by spaces)
Hi Chris,
How would you add this to your chatrooms.coffee.erb or a last_read.coffee from the chat application? Not sure how to translate it in coffee script.
Stan
Hi!
What should I do if I want some channel work with current_user and some channels work with Unauthenticated user (just visitors)? How do I modify channels/application_cable/connection.rb or channels/some_channel.rb ?
Is it possible?
Thank you very much!
Is this method supposed to work with the new way of handling JS in Rails through Webpacker?
Can't get it to work I am assuming because the files no longer have view of the metatag on the page and so the if statement always returns false...
Thanks!
Got this to work by putting it above the JS pack tag in the head and wrapping the if statement around the require("channels");
in our appication.js
...