Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

Disabling ActionCable for Unauthenticated Users Discussion

General • Asked by Chris Oliver

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 or a from the chat application? Not sure how to translate it in coffee script.

This tool can translate to and from Coffeescript: 👍

yes. was my immediate attempt but...still no success.

What are you having trouble with? The if statements around your code should be mostly the same.

I added
if $("meta[name='current-user']").length >0
above the
App.chatrooms = App.cable.subscriptions.create "ChatroomsChannel"

but this leads to
SyntaxError: [stdin]:1:1: unexpected if

Can you share your whole file?

For readers of these comments, the issue was with the indentation. Beware of coffeescript on that side! Thks Chris again for your help.

Does anyone have a working coffee version of the project files t. I'm unable to get "an unauthorized attempt..." to stop even though I've made the changes. When the user isn't on the chatrooms_controller, it shouldn't be searching for that user. Please, assist me -- I've been working on this thing for a few weeks now.
I think its finally working. I'm no longer receiving the message while in other controllers.


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!

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 30,005+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.